git - 在每次提交时分别运行 go fmt 时,是否有任何工具会重新设置 Git 中的分支?

标签 git go indentation git-rebase gofmt

我希望使用 go fmtindent 等源代码格式化工具重建/ 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/

相关文章:

python - Emacs 缩进不识别 Python 模式中的变量

git ls-files : howto identify new files (added, 未提交)?

git - 如何限制对 git 上的 master 分支的访问

go - 如何将 []int 转换为 [2]int?

c++ - 在 Codegear RAD Studio 中缩进

python - 为什么可以混合python缩进

Git 只克隆 .git 文件夹。不是所有文件

linux - 将 Git 同步到服务器

go - 无法将所有日志语句写入文件

unit-testing - 在辅助函数中包装 httptest 方法