Git rebase:合并非随后的提交 [英] Git rebase: Combine non-subsequent commits
问题描述
情况:
$ b $
$ git rebase --interactive HEAD ^^^^
pick 5b7c140 commitA
pick 40ffd7c commitB
pick 5e7647d commitC
pick 78bea2d commitD
Rebase [...]
是否还可以处理以下要求:
将commitA和commitC以及commitB和commitD组合到新提交cAC和cBD中? / p>
这是可能的 - 您还可以使用交互式rebase重新排列提交顺序:
pick 5b7c140 commitA
squash 5e7647d commitC
pick 40ffd7c commitB
squash 78bea2d commitD
或
选择5b7c140 commitA
fixup 5e7647d commitC
挑40ffd7c commitB
fixup 7 8bea2d commitD
两者的区别在于 squash
允许您编辑新提交的提交消息,而 fixup
只是抛出第二个提交消息而离开前面的 pick
提交合并提交的消息。 (如果你的编辑器启动得足够快,那么只要选择 squash
就可以让你有机会查看提交信息,即使你认为你可能不需要使用部分消息 fixup
提交。)
如果您的 commitB
和 commitC
改变文件的同一部分。通常这些可以很容易地被整理出来。
by now, I know that there is a nice way how to combine commits and change the commit message by using 'git rebase --interactive'
Having the following situation:
$ git rebase --interactive HEAD^^^^
pick 5b7c140 commitA
pick 40ffd7c commitB
pick 5e7647d commitC
pick 78bea2d commitD
Rebase [...]
Is there also a possibility to handle the following requirements:
Combining commitA and commitC and commitB and commitD to new commits cAC and cBD?
It is possible - you can also rearrange the order of the commits with interactive rebase:
pick 5b7c140 commitA
squash 5e7647d commitC
pick 40ffd7c commitB
squash 78bea2d commitD
or
pick 5b7c140 commitA
fixup 5e7647d commitC
pick 40ffd7c commitB
fixup 78bea2d commitD
The difference between the two is that squash
allows you to edit the commit message for the new commits, whereas fixup
just throws away the second commit message leaving the preceeding pick
commit message in place for the combined commit. (If your editor launches quickly enough, then having the habit of just choosing squash
gives you a nice opportunity to review the commit message even if you think you would probably not need to use parts of the message of the fixup
commit.)
There is a possibility of rebase conflict, if your commitB
and commitC
change a same part of a file. Often these can be easily enough sorted out.
这篇关于Git rebase:合并非随后的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!