Skip to main content
2 of 8
added 969 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 ....

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

  7. Now push to logs. Note to add + sign before the branch name.

    #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