Video in progress
Before a PR, how do you clean up commits on the branch like "wip", "fix typo" and "review fixes"?
With git rebase -i (interactive rebase): you squash/fixup the unneeded commits into the main ones, fix messages with reword, and reorder. This is done only on a personal branch.
📖 Answer
git rebase -i origin/main
An editor opens:
pick 1a2b3c4 Hisobot uchun DTO va repository
pick 5d6e7f8 wip
pick 9a0b1c2 Hisobot controller'i
pick 3d4e5f6 fix typo
We change it:
pick 1a2b3c4 Hisobot uchun DTO va repository
fixup 5d6e7f8 wip
pick 9a0b1c2 Hisobot controller'i
fixup 3d4e5f6 fix typo
fixup folds the commit into the previous one and drops its message; squash opens an editor so you can combine the messages; drop deletes it; edit stops at that commit so you can change it.
You can also plan ahead: save a review fix with git commit --fixup=1a2b3c4, and then git rebase -i --autosquash origin/main puts them in the right place by itself.
At the end, git push --force-with-lease. If the team squash-merges the PR anyway, this work matters less, but logically split commits are still convenient for the reviewer.
Sign up to mark studied questions and save your progress.