我希望使用 go fmt
或 indent
等源代码格式化工具重建/ rebase Git 分支 X
中的所有提交。
我希望工作流程大致包括从 master
中创建一个新分支并使用 $_
迭代以下内容,范围遍及 X< 中的提交
:
git cherry-pick $_
go fmt ...
git commit -a --amend
甚至可能
git cherry-pick -n $_
go fmt ...
git cherry-pick --continue
不过,我不希望 -n
和 --continue
像那样一起玩。此外,人们应该自然而然地执行 go fmt
提交到 X
并在完成后 go diff X new
。
但是,此过程中有许多步骤可能会出错,例如 -a
试图更改原始提交中未更改的文件,go fmt
混淆 Git 的补丁,Git 更改提交日期等。
这些都不是特别麻烦,但如果有一个快速工具或更简单的工作流程可以更干净地完成此操作,那么我很想知道它。
最佳答案
but if a quick tool or simpler workflow does this more cleanly, then I'd love to know about it.
作为Joseph K. Strauss提及 in the comments , git filter-branch
应该够了,加上go fmt
using the three dot notation :
git filter-branch --tree-filter 'go fmt ...'
您可以在“git filter-branch
- discard the changes to a set of files in a range of commits”中阅读更多关于 filter-branch 的内容。
该命令将针对所有本地分支运行,并将更改历史记录(因为将为每个修改的提交生成新的 SHA1)。
可能需要 git push --force
将新历史发布到其上游存储库:一定要警告其他协作者,让他们重置本地存储库。
关于git - 在每次提交时分别运行 go fmt 时,是否有任何工具会重新设置 Git 中的分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27738571/