0
0
Gitdevops~10 mins

Squashing commits in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Squashing commits
Start: Multiple commits
Run git rebase -i HEAD~N
Editor opens with commit list
Mark commits as 'squash' or 'fixup'
Save and close editor
Git combines commits
Edit combined commit message
Save and close editor
Rebase completes with squashed commit
Result: Single combined commit
Squashing combines multiple commits into one by interactive rebasing and editing commit messages.
Execution Sample
Git
git rebase -i HEAD~3
# In editor, mark second and third commits as 'squash'
# Save and close editor
# Edit combined commit message
# Save and close editor
This sequence squashes the last 3 commits into one commit with a combined message.
Process Table
StepActionGit StateUser InputResult
1Run 'git rebase -i HEAD~3'Last 3 commits separateNoneEditor opens with 3 commits listed
2Mark commits to squashEditor shows commitsMark 2nd and 3rd commits as 'squash'Commits marked for squashing
3Save and close editorGit starts rebasingNoneGit combines the commits into 1
4Edit combined commit messageRebase paused for message editWrite combined commit messageCommit message updated
5Save and close editorRebase continuesNoneRebase completes with 1 squashed commit
6Check git logOne combined commit replaces 3NoneHistory shows single squashed commit
💡 Rebase completes successfully with commits squashed into one.
Status Tracker
VariableStartAfter Step 3After Step 5Final
Commit count31 (after squash)11
Commit messages"A", "B", "C""A + B + C combined""A + B + C combined""A + B + C combined"
Key Moments - 3 Insights
Why do we need to mark commits as 'squash' in the editor?
Marking commits as 'squash' tells Git which commits to combine. Without this, Git won't know which commits to merge. See execution_table step 2.
What happens if you don't edit the combined commit message?
Git will use the default combined message from all commits. Editing lets you write a clear, single message. See execution_table step 4.
Why does the rebase pause after combining commits?
It pauses to let you edit the new commit message before finishing. This ensures the final commit message is meaningful. See execution_table step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does Git combine the commits?
AStep 3
BStep 2
CStep 5
DStep 1
💡 Hint
Check the 'Result' column in step 3 where commits are combined.
According to the variable tracker, how many commits remain after step 5?
A3
B1
C2
D0
💡 Hint
Look at 'Commit count' after step 5 in variable_tracker.
If you forget to mark commits as 'squash' in the editor, what happens?
AGit will combine all commits anyway
BGit will abort the rebase
CGit will leave commits separate
DGit will delete commits
💡 Hint
Refer to execution_table step 2 where marking commits is required.
Concept Snapshot
git rebase -i HEAD~N
# Opens editor with last N commits
# Mark commits as 'squash' or 'fixup' to combine
# Save and close editor to start rebase
# Edit combined commit message
# Save and close to finish
Result: Multiple commits become one with combined message
Full Transcript
Squashing commits means combining several commits into one. You start by running 'git rebase -i HEAD~N' where N is how many commits back you want to combine. Git opens an editor listing those commits. You mark the commits you want to squash by changing 'pick' to 'squash' or 'fixup'. After saving and closing the editor, Git combines those commits into one. It then pauses so you can edit the new combined commit message. After saving that, the rebase finishes. The commit history now shows one single commit instead of many. This helps keep history clean and easier to understand.