Page tree
Skip to end of metadata
Go to start of metadata

Squashing commits: combining multiple existing commits

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.

Fetch another developer's branch for testing

Example: I have been asked to test changes made to IGB on another developers branch as part of a 1st level review.

Find the developers IGB repository URL.

Type the following in a terminal or git bash:

git fetch https://bitbucket.org/nfreese/nowlanfork-igb.git IGBF-3379:IGBF-3379-myBranch
git checkout IGBF-3379-myBranch

This will fetch the branch IGBF-3379 from the developer's repository, and it will call that branch IGBF-3379-myBranch on your local machine. You can then checkout the branch and test it.

Note: This local branch will not track the developer's remote branch. 

  • No labels