Skip to main content
5 of 8
added 91 characters in body
rashok
  • 13.2k
  • 17
  • 90
  • 101
  1. 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.

  2. If you want to squash (merge) last two commit

    git rebase -i deab3412

  3. 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 ....

  4. Rename the word pick to squash which is present before abcd1234. After rename it should be like below.

    .... pick cdababcd Fix issue B squash abcd1234 Update to Fix for issue B ....

  5. Now save and close the nano editor. Press ctrl + o and press Enter to save. And then press ctrl + x to exit the editor.

  6. Then nano editor again opens for updating comments, if necessary update it.

  7. 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 ....

  8. 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.

rashok
  • 13.2k
  • 17
  • 90
  • 101