Git Commit Squash

If your commits on local not pushed to remote

combine local commits, you could follow this flow

Here is short video (only 3 minutes) and good explanation of git rebase -i usage.

list your local repository log

list your logs in oneline

If you want to combine these 3 commits (add6152, 3650100, 396a652) to 1 commit, execute this command

git rebase -i HEAD~3      # last three commits

list last three commits

Select which commit you want to squash (type s or squash are OK)

combine three commits to one

then press ESC, enter :wq! to save and exit.

comment out some commits message you don't need

Comment out some commits message you don’t need, press ESC, enter :wq! to save and exit.

comment out some commits message you don't need

Check log, you will see your local repository logs has combine to one commit

comment out some commits message you don't need

If your commits had pushed to remote

combine remote commits, you could follow this flow

list your repository logs

list your logs in oneline

# so you can create another branch from bugfix/UNV-1234 named bugfix/UNV-1234-for-squash
xshen@dln-l-xs01 MINGW64 /c/U2GitCode/git-test (bugfix/UNV-1234)
$ git checkout -b bugfix/UNV-1234-for-squash
Switched to a new branch 'bugfix/UNV-1234-for-squash'

# combine last 2 commits
$ git rebase -i HEAD~2

change one commit from pick to squash, see the screenshot below. press ESC, enter :wq! to save and exit.

select a commit you want to squash

change commit message, for example “UNV-1234 combine all commit to one commit”, then press ESC, enter :wq! to save and exit.

comment out commit message you don't want to display

# push your new create branch to remote.
git push -u origin bugfix/UNV-1234-for-squash