Open Joldnine opened 6 years ago
Sometimes we want to ‘squash’ multiple commits into one. We can always do it by interactive rebase. Example:
rebase
$ git log --oneline
We have:
5f2f5fb commit-3 2506e7a commit-2 2800c01 commit-1 12s21f commit-0
We hope to merge three commits (commit-1, commit-2 and commit-3) into one.
Steps: $ git rebase -i 12s21f
$ git rebase -i 12s21f
pick 2800c01 commit-1 pick 2506e7a commit-2 pick 5f2f5fb commit-3 ....
pick 2800c01 commit-1 pick 2506e7a commit-2 pick 5f2f5fb commit-3
....
Modify it into:
pick 2800c01 commit-1 s 2506e7a commit-2 s 5f2f5fb commit-3 ....
pick 2800c01 commit-1 s 2506e7a commit-2 s 5f2f5fb commit-3
We save it by: Press esc wq Enter
wq
After it, we will be asked to edit the commit message; edit and save it by Press esc wq Enter
Done!
Sometimes we want to ‘squash’ multiple commits into one. We can always do it by interactive
rebase
. Example:We have:
We hope to merge three commits (commit-1, commit-2 and commit-3) into one.
Steps:
$ git rebase -i 12s21f
We have:
Modify it into:
We save it by: Press esc
wq
EnterAfter it, we will be asked to edit the commit message; edit and save it by Press esc
wq
EnterDone!