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
git rebase -i HEAD~3Opens your last three commits in the editor, oldest at the top. Use a different number for more or fewer.
Leave the first line as
pick. On every other line, changepicktosquash(or justs). Save and close.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.
git rebase -i HEAD~3Why 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.