Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "squash" and "fixup" in Git/Git Extension?

People also ask

What does fixup do in git?

Fixup commits Practically, --fixup associates a new commit with an existing commit so that when you do an interactive rebase, you don't have to re-order any commits in order to squash them. And you don't have to change any commit messages.

What is squash in git rebase?

With “squash”, you can merge all of your commits from a feature branch into a single commit, which can then be added to the end of the main branch. In this example, after the 2 feature branches have been rebased and merged in, instead of being 3 commits each, they're now just 1.

What is git squash commit?

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.

How do you squash git?

If you want to squash a commit into a previous one and discard the commit message, enter f in the place of the pick of the commit. Save and quit your text editor. When rebase is stopped, make the necessary adjustments, then use git rebase --continue until rebase is successful.


I do not know what Git Extensions does with it specifically, but git rebase has an option to automatically squash or fixup commits with squash! or fixup! prefixes, respectively:

   --autosquash, --no-autosquash
       When the commit log message begins with "squash! ..." (or "fixup!
       ..."), and there is a commit whose title begins with the same ...,
       automatically modify the todo list of rebase -i so that the commit
       marked for squashing comes right after the commit to be modified,
       and change the action of the moved commit from pick to squash (or
       fixup).

The difference between squash and fixup is that during the rebase, the squash operation will prompt you to combine the messages of the original and the squash commit, whereas the fixup operation will keep the original message and discard the message from the fixup commit.


Simply put, when rebasing a series of commits, each commit marked as a squash, gives you the opportunity to use its message as part of a pick or reword commit message.

When you use fixup the message from that commit is discarded.


If the question is what's the difference between squash and fixup in git when doing git rebase --interactive, then the answer is the commit message.

s, squash <commit> = use commit, but meld into previous commit

f, fixup <commit> = like "squash", but discard this commit's log message


For example:

pick 22a4667 father commit message
squash 46d7c0d child commit message # case 1
# fixup 46d7c0d child commit message # case 2

The commit message after rebasing in case 1 would be:

father commit message

child commit message

while the commit message in case 2 is:

father commit message
# no sub messages

From git-rebase doc, "interactive mode" section:

If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit message for the folded commit is the concatenation of the commit messages of the first commit and of those with the "squash" command, but omits the commit messages of commits with the "fixup" command.


Both squash and fixup will allow code changes to be introduced by their respective diff's. (not normally mentioned)

The distinction between squash and fixup is in how the commit messages are treated.

In the fixup case the original commit message is kept, unchanged, and any text within the fixup commit message is ignored (unceremoniously dumped).

In the squash case both commit messages are combined ('melded'), one after the other, and offered to the user's editor, so that they can be amalgamated/fused together as desired by the user.

The initial combined message (squash) will contain comment marks showing where the messages start and end. Multiple squash and fixups can be applied.

The terminology can be confusing when discussing small code corrections (without need to change the message) as often one may suggest that the code is 'squeezed' in, when a squash isn't actually required.


I tinkered with git extensions and couldn't get it to squash many commits into one. To do that, I had to resort to the command line and found this post helpful

git rebase -i Head~2

This is interactive rebase, and note the following:

  • ~2 here refers to how many commits you want to involve in this operation, including the current head
  • You have to edit the subsquent interactive edit window, leave the first item as "pick" and replace subsequent lines with "squash". The instructions in the link above are much clearer if this is opaque.