Home > Software engineering >  Fixup commits are not squashed
Fixup commits are not squashed

Time:11-11

I've discovered Git's fixup/autosquash feature and want to give it a try. Unfortunately, I'm having issues with squashing some fixup commits.

This is my current Git history when running git log --oneline -n 4:

95686a33 (HEAD -> feature/ABC-1234-My-Feature, origin/feature/ABC-1234-My-Feature) fixup! feat: implement my feature
ac56a2ee fixup! feat: implement my feature
de904aa3 fixup! feat: implement my feature
cc3a205b feat: implement my feature

Now I'm running git rebase -i --autosquash cc3a205b and the editor opens with the following content:

pick de904aa3 fixup! feat: implement my feature
pick ac56a2ee fixup! feat: implement my feature
pick 95686a33 fixup! feat: implement my feature

# Rebase cc3a205b..95686a33 onto cc3a205b (3 commands)

I'm closing the editor without changing anything, leading to the following output:

Successfully rebased and updated refs/heads/feature/ABC-1234-My-Feature.

When executing git log --oneline -n 4 again, the 3 fixup commits are still present.

I expected the history to only contain the single commit feat: implement my feature with a new Git commit ID, but without the fixup commits.

Am I doing something wrong or do I have the wrong expectations?

Running git --version returns git version 2.38.1.windows.1, so I'm using the latest version.

CodePudding user response:

The problem is that your pick list does not contain the commit into which you want to merge your fixups:

pick de904aa3 fixup! feat: implement my feature
pick ac56a2ee fixup! feat: implement my feature
pick 95686a33 fixup! feat: implement my feature

Note that your feat: implment my feature commit doesn't show up there. Without that, Git cannot recognize these as fixup commits and there's nothing for them to merge into.

You need to rebase against cc3a205b^ (the parent of cc3a205b) instead:

git rebase -i --autosquash cc3a205b^
  •  Tags:  
  • git
  • Related