0
0
Gitdevops~10 mins

Interactive rebase (git rebase -i) - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Interactive rebase (git rebase -i)
Start: git rebase -i HEAD~3
Open editor with last 3 commits
User edits commands (pick, squash, reword)
Save and close editor
Git applies commits one by one
If conflict
Resolve conflict
git rebase --continue
Rebase finishes successfully
Updated commit history
Interactive rebase lets you edit, reorder, squash, or fix commits by opening an editor and applying changes step-by-step.
Execution Sample
Git
git rebase -i HEAD~3
# Edit commands in editor
# Save and close
# Resolve conflicts if any
# git rebase --continue
This command starts an interactive rebase of the last 3 commits allowing you to modify commit history.
Process Table
StepActionEditor ContentGit AppliesResult
1Run 'git rebase -i HEAD~3'Shows last 3 commits with 'pick' commandsNo commits applied yetEditor open for user commands
2User changes second commit from 'pick' to 'squash'First commit pick, second squash, third pickNo commits applied yetWaiting for user to save and close editor
3User saves and closes editorCommands acceptedGit applies first commitFirst commit applied successfully
4Git applies second commit (squash)Squashes second commit into firstCombines commit messagesCommit history updated with combined commit
5Git applies third commitPick third commitThird commit appliedAll commits applied successfully
6Rebase completeNo editorNo actionCommit history rewritten with changes
💡 All commits applied or combined; rebase finished successfully
Status Tracker
VariableStartAfter Step 3After Step 4After Step 5Final
Commit HistoryC1 - C2 - C3C1 - C2 - C3C1+2 (squashed) - C3C1+2 - C3C1+2 - C3 (final)
Editor StateClosedClosedClosedClosedClosed
Rebase StatusNot startedApplying commitsApplying commitsApplying commitsFinished
Key Moments - 3 Insights
Why does git open an editor during interactive rebase?
Git opens the editor to let you choose what to do with each commit (pick, squash, reword). This is shown in execution_table step 1 and 2.
What happens if you change 'pick' to 'squash' for a commit?
The commit is combined with the previous one, merging their changes and messages. See execution_table step 4 for this action.
How do you continue the rebase after resolving conflicts?
You run 'git rebase --continue' to tell git to proceed applying commits. This is part of the flow after conflicts, shown in concept_flow.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the commit history after step 4?
AC1 - C3
BC1 - C2 - C3
CC1+2 (squashed) - C3
DC2 - C3
💡 Hint
Check the 'Commit History' row in variable_tracker after step 4
At which step does the user save and close the editor?
AStep 1
BStep 3
CStep 2
DStep 5
💡 Hint
Look at the 'Action' column in execution_table where editor commands are accepted
If the user changes all 'pick' commands to 'reword', what changes in the process?
AGit prompts to edit commit messages one by one
BCommits are reordered
CCommits are combined
DRebase stops immediately
💡 Hint
Recall what 'reword' means in interactive rebase and how git applies commits
Concept Snapshot
git rebase -i HEAD~N
- Opens editor with last N commits
- Commands: pick, squash, reword, etc.
- Save and close to apply changes
- Resolve conflicts if any, then git rebase --continue
- Rewrites commit history interactively
Full Transcript
Interactive rebase with 'git rebase -i' lets you change commit history by opening an editor showing recent commits. You can pick, squash, or reword commits. After editing commands, git applies commits one by one, combining or changing them as instructed. If conflicts occur, you resolve them and continue. This process updates your commit history cleanly and interactively.