Identify the commit short hash
git log --pretty=oneline --abbrev-commit
abcd1234 Update to Fix for issue B cdababcd Fix issue B deab3412 Fix issue A .... Here even
git log --oneline
also can be used to get short hash.If you want to squash (merge) last two commit
git rebase -i deab3412
This opens up a
nano
editor for merging. And it looks like below.... pick cdababcd Fix issue B pick abcd1234 Update to Fix for issue B ....
Rename the word
pick
tosquash
which is present beforeabcd1234
. After rename it should be like below..... pick cdababcd Fix issue B squash abcd1234 Update to Fix for issue B ....
Now save and close the
nano
editor. Pressctrl + o
and pressEnter
to save. And then pressctrl + x
to exit the editor.Then
nano
editor again opens for updating comments, if necessary update it.Now its squashed successfully, you can verify it by checking logs.
git log --pretty=oneline --abbrev-commit
1122abcd Fix issue B deab3412 Fix issue A ....
Now push to repo. Note to add
+
sign before the branch name. This means forced push.git push origin +master
Note : This is based on using git on ubuntu
shell. If you are using different os (Windows
or Mac
) then above commands are same except editor. You might get different editor.