Git squash

The goal is to squash the latest 4 commits into one.

git rebase -i HEAD~4

In the vi editor:

Change

pick 01d1124 Message....
pick 6340aaa Message....
pick ebfd367 Message....
pick 30e0ccb Message....

to

p 01d1124 Message....
s 6340aaa Message....
s ebfd367 Message....
s 30e0ccb Message....

Later in the next vi editor, edit the commie messages, comment the useless commits with #, and save the needed one.

Be aware:

pick the toppest commit and squash the rest, otherwise an error will show up Cannot 'squash' without a previous commit.

你可能感兴趣的:(Git squash)