Joldnine / joldnine.github.io

My github.io blog repo. https://joldnine.github.io
2 stars 1 forks source link

Git: git squash #23

Open Joldnine opened 6 years ago

Joldnine commented 6 years ago

Sometimes we want to ‘squash’ multiple commits into one. We can always do it by interactive rebase. Example:

$ 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

We have:

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

....

We save it by: Press esc wq Enter

After it, we will be asked to edit the commit message; edit and save it by Press esc wq Enter

Done!