Git rebase: Combine non-subsequent commits

℡╲_俬逩灬. 提交于 2019-12-23 07:50:04

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/15406093/git-rebase-combine-non-subsequent-commits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!