All fixes

Help, I made too many tiny commits and want to squash them

Turn “wip”, “fix typo” and “wip 2” into one clean commit before anyone reviews your branch.

The fix

  1. git rebase -i HEAD~3

    Opens your last three commits in the editor, oldest at the top. Use a different number for more or fewer.

  2. Leave the first line as pick. On every other line, change pick to squash (or just s). Save and close.

  3. Git opens the editor once more with all the messages. Write one good message, save and close. Done.

3 is an example. Replace it with your own.

This rewrites the commits. If you already pushed them, push again with git push --force-with-lease, and only on your own branch.

What happens to your historygit rebase -i HEAD~3
BeforeABCDmainHEADfeature/login
AfterASmainHEADfeature/login

Why this works

Interactive rebase replays your last commits one by one and lets you decide what happens to each. squash melts a commit into the one above it, so the first line has to stay pick. There is also a shortcut without the editor: git reset --soft HEAD~3 followed by git commit -m "Add login form" turns the last three commits into one.