Example:
I have three commits on my branch for a single Jira ticket. I would like to squash them into a single commit before creating a pull request.
While on my branch, type:
git rebase -i HEAD~3 |
This will open the default editor on your machine and display something like the following:
pick afb581 IGBF-3379: Fix DAS annotations pick 643d0e IGBF-3379: Fix typo pick 87871a IGBF-3379: Fix second typo |
Note that the oldest commit is on top, and the newer commit is on the bottom.
To squash the two newer commits into the older commit, change pick to squash:
pick afb581 IGBF-3379: Fix DAS annotations squash 643d0e IGBF-3379: Fix typo squash 87871a IGBF-3379: Fix second typo |
Save and then close the editor.
The editor will open again showing the commits and their messages.
# This is a combination of 3 commits. # This is the 1st commit message: IGBF-3379: Fix DAS annotations # This is the commit message #2: IGBF-3379: Fix typo # This is the commit message #3: IGBF-3379: Fix second typo |
My preference is to remove the commit messages for the two squashed commits. You can also update the initial commit message if needed.
# This is a combination of 3 commits. # This is the 1st commit message: IGBF-3379: Fix DAS annotations and typos # This is the commit message #2: # This is the commit message #3: |
Save and then close the editor.