在使用Git作為版控時,會提交許多大大小小的commit,而把這些commit拼湊起來才會是一個完整的任務,為了避免太多的commit造成版控的混亂,就會將這些commit給壓縮成一個完整的名稱。
log。$ git log
commit。方法一、此步驟是指此從HEAD開始數來到第三個commit,包含自身。
$ git rebase -i HEAD~3
方法二、此步驟是指此版本號之前的commit,不包含自身。
$ git rebase -i 版本號
rebase命令後會看到所要合併的commit。pick 6cdfbc0 '注释**********'
pick 793ee97 '注释*********'
pick 879e453 '注释**********'
pick改成squash或s然後儲存關閉編輯。pick 6cdfbc0 '注释**********'
s 793ee97 '注释*********'
s 879e453 '注释**********'
commit完後儲存關閉編輯。This is a combination of 4 commits.
#The first commit’s message is:
注释......
The 2nd commit’s message is:
注释......
The 3rd commit’s message is:
注释......
Please enter the commit message for your changes. Lines starting # with ‘#’ will be ignored, and an empty message aborts the commit.
log,就會發現已把上述commit給合併完成。ps. 放棄此次commit壓縮
$ git rebase --abort