Squashing Multiple Commits In Git

Here’s how I create a patch that squashes multiple commits into one, making it easier for the maintainer to review in a project or if you’re working with SVN repo.

Assumptions:

  • The work is done at “working” branch.
  • You’re merging in your changes to “master”
  • “tmp” branch will be used to create the patch
  • The patch will be placed in your Desktop (remember, I use Mac)

Steps:

  • from “master”,
    git checkout -b tmp
  • fetch the squashed commit.
    git merge --squash working
  • commit the differences.
    git commit -a -m "your commit comment"
  • create the patch.
    git format-patch -o ~/Desktop/ master
  • apply patch and clean up.
    git checkout master
    git am ~/Desktop/{name of the patch}
    git branch -D tmp

At this point, you may also want to remove working branch and create a fresh branch.

Comments

Comments are closed.

Powered by Olark