英文:
Any tools rebase a branch in Git while running go fmt each commit separately?
问题
我希望使用像go fmt
或indent
这样的源代码格式化工具来重建/重新基于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
可以这样一起使用。完成后,我会在X
上进行一个go fmt
提交,并使用go diff X new
进行比较。
然而,这个过程中可能会出现许多问题,比如-a
试图更改原始提交中未更改的文件,go fmt
混淆了Git的补丁,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.
答案1
得分: 1
但是如果有一个更简洁的工具或者更简单的工作流能更干净地完成这个任务,那我很想知道。
正如Joseph K. Strauss在评论中提到的那样,git filter-branch
应该足够了,再加上使用三个点符号的go fmt
:
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
将新的历史发布到上游仓库:请提醒其他协作者重置他们的本地仓库。
英文:
> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论