Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Extensions: Squash commits?

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.

like image 701
Slaknation Avatar asked Oct 13 '17 15:10

Slaknation


People also ask

Should you squash commits Git?

Before you start, keep in mind that you should squash your commits BEFORE you ever push your changes to a remote repository. If you rewrite your history once others have made changes to it, you're asking for trouble… or conflicts.

What is the meaning of squash commits in Git?

What does it mean to squash commits in Git? Squashing is a way to rewrite your commit history; this action helps to clean up and simplify your commit history before sharing your work with team members. Squashing a commit in Git means that you are taking the changes from one commit and adding them to the Parent Commit.


Video Answer


1 Answers

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

like image 188
RussKie Avatar answered Sep 27 '22 18:09

RussKie