在分支BRANCH_SOMETHING上有这样的情况:
FFF - 6th commit
EEE - 5th commit
DDD - 4th commit
Y commit from master
X commit from master
CCC - 3rd commit
BBB - 2nd commit
AAA - 1st commit
如何仅压缩我的提交?
答案 0 :(得分:2)
您必须运行的命令是git rebase -i AAA~
(请注意~
)
它将使用以下rebase程序打开您的默认文本编辑器:
pick AAA 1st commit
pick BBB 2nd commit
pick CCC 3rd commit
pick X commit from master
pick Y commit from master
pick DDD 4th commit
pick EEE 5th commit
pick FFF 6th commit
您必须将文本编辑为这样:
pick X commit from master
pick Y commit from master
pick AAA 1st commit
squash BBB 2nd commit
squash CCC 3rd commit
squash DDD 4th commit
squash EEE 5th commit
squash FFF 6th commit
保存并退出文本编辑器。
Git将运行,然后再次打开文本编辑器,使您有机会编辑提交消息:
# This is a combination of 6 commits.
# This is the 1st commit message:
1st commit
# This is the commit message #2:
2nd commit
...
编辑提交消息,保存并退出。
最后,历史将如下所示:
GGG squashed commit
Y commit from master
X commit from master
请注意,您还可以将提交X和Y放置在被压缩的提交之后,相应地突出显示重新设置程序。
答案 1 :(得分:0)