One basic rule of keeping the repository clean is keeping commits meaningful. I have shared a [blogpost][1] & [20-minute-long-video][2] how you can do it via rebase features, in this blogpost I will summarize how to do it via fixup commit.

In my feature branch, I have prepared two commits, two logically well-separated commits. While testing afterwards, I have figured that something was wrong with the first commit. I could just fix it and commit it, but then I’d have committed an unnecessary change. It would stay in the history forever.

Instead, I run the commit command with –fixup parameter. The value of this parameter is the hash of the previous commit. Then, two squash this commit to the first commit, we run:

git rebase -i --autosquash master

I have rebased my branch onto master, but you can also use HEAD~3 instead; it rebases the same branch onto itself but 3 commit before.

In the interactive rebase screen, git placed fixup commit in the second line and changed its command as fixup, so that fix commit will be squashed into the first commit. When I saved and exited the editor, two commits remained the same, without introducing a new bogus commit.

You can check my [blogpost][1] & [20-minute-long-video][2] for push strategies after this point.

History remained clean, the day is saved. [1]: [2]: