duandi8544
2015-01-02 06:59
浏览 88

在运行go fmt每个提交时,是否有任何工具可以在Git中重新建立分支的基础?

I wish to rebuild/rebase all commits in a Git branch X using a source code formatting tool like go fmt or indent.

I'd expect the workflow to roughly consist of making a new branch off master and iterating the following with $_ ranging over the commits in X:

git cherry-pick $_
go fmt ...
git commit -a --amend

Or maybe even

git cherry-pick -n $_
go fmt ...
git cherry-pick --continue

I wouldn't expect -n and --continue to play together like that, though. Also, one should naturally do a go fmt commit to X and go diff X new when done.

However, there are many steps that can go wrong with this procedure, like the -a seeking to change files that weren't changed in the original commit, go fmt confusing Git's patching, Git changing the commit dates, etc.

None of that is particularly troublesome, but if a quick tool or simpler workflow does this more cleanly, then I'd love to know about it.

图片转代码服务由CSDN问答提供 功能建议

我希望使用源代码在Git分支 X 中重建/重新设置所有提交 格式工具,例如 go fmt indent

我希望工作流程大致包括在 master 上创建一个新分支,并在整个范围内用 $ _ 迭代以下内容 X 中的提交:

  git cherry-pick $ _ 
go fmt ... 
git commit -a --amend 
   
 
 

或者甚至

  git cherry-pick -n $ _ 
go fmt ... 
git cherry-pick-  -continue 
   
 
 

我不希望 -n -continue 这样一起玩, 虽然。 同样,完成后自然应该对 X go diff X new 进行 go fmt 提交。 < p>但是,此过程有很多步骤可能出错,例如 -a 试图更改原始提交中未更改的文件 go fmt

这些都不是特别麻烦,但是如果使用快速工具或更简单的工作流程可以更干净地做到这一点,那么我很想知道 关于它。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drs7798 2015-01-02 15:56
    已采纳

    but if a quick tool or simpler workflow does this more cleanly, then I'd love to know about it.

    As Joseph K. Strauss mentions in the comments, git filter-branch should be enough, plus go fmt using the three dot notation:

    git filter-branch --tree-filter 'go fmt ...'
    

    You can read (much) more on filter-branch at "git filter-branch - discard the changes to a set of files in a range of commits".

    That command will run against all local branch, and will change the history (since new SHA1 will be generated for each modified commit).
    A git push --force might be needed to publish the new history to its upstream repo: do warn the other collaborators, for them to reset their local repos.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题