Git Extensions: Squash commits?

Slaknation picture Slaknation · Oct 13, 2017 · Viewed 17.4k times · Source

To squash multiple commits, I have always used:

git reset --soft HEAD~<number of commits to squash> && git commit

But I wonder if there is a good way to do this in a good git client like git extensions? It would be cool if you could just select consecutive commits and squash them.

Answer

RussKie picture RussKie · Nov 23, 2017

There are multiple ways of doing a squash.

Here's how you can easily squash the current and all its immediate parent commits into a single commit in Git Extensions:

  1. Right click on a commit you wish to squash to and select "Reset the current branch to here"
  2. Select either "Soft reset" (retain staged files) or "Mixed reset" (unstage all files)
  3. Stage, if necessary
  4. Commit

Here's an animation of the above:

enter image description here


Another way is to do an "interactive rebase" either

  • via a command line (git rebase -i, read docs), or
  • via UI (e.g. Git Extensions).

To do an interactive rebase in Git Extensions:

  1. Right click on a commit you wish to squash to and select "Rebase current branch on > Selected commit interactively..."
  2. In the presented dialog alter the history, such as choose which commits to squash or reword
  3. Save and close

Here's an animation of the above:

enter image description here