How do you combine multiple commits into a single commit?
⚡
Quick Answer
Use an interactive rebase: git rebase -i HEAD~n, then mark the commits you want to fold with squash (or fixup) in the editor. This rewrites them into one.
Detailed Answer
squash keeps the commit messages for you to edit into one; fixup discards the squashed commits messages. Squashing produces a clean, reviewable history (one logical change per commit) and is common before merging a feature branch. Because it rewrites history, only do it on commits you have not shared, or force-push your own branch.
Code Example
git rebase -i HEAD~3 # mark commits as squash/fixup
💡
Interview Tip
Mention squash vs fixup and that it rewrites history, so only squash unshared commits (or force-push your own branch).
gitrebasesquash