交互式的衍合工具还可以将一系列提交压制为单一提交。脚本在 rebase 的信息里放了一些有用的指示:
[code]#
Commands:
p, pick = use commit
e, edit = use commit, but stop for amending
s, squash = use commit, but meld into previous commit
If you remove a line here THAT COMMIT WILL BE LOST.
However, if you remove everything, the rebase will be aborted.
#[/code]
如果不用"pick"或者"edit",而是指定"squash",Git 会同时应用那个变更和它之前的变更并将提交说明归并。因此,如果你想将这三个提交合并为单一提交,你可以将脚本修改成这样:
pick f7f3f6d changed my name a bit
squash 310154e updated README formatting and added blame
squash a5f4a0d added cat-file
当你保存并退出编辑器,Git 会应用全部三次变更然后将你送回编辑器来归并三次提交说明。
[code]# This is a combination of 3 commits.
The first commit’s message is:
changed my name a bit
This is the 2nd commit message:
updated README formatting and added blame
This is the 3rd commit message:
added cat-file[/code]
当你保存之后,你就拥有了一个包含前三次提交的全部变更的单一提交。
REF:http://cwiki.ossez.com/pages/viewpage.action?pageId=7045538