Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Editing commit messages with rebase
📖 Scenario: You have made several commits in your local Git repository. Now, you want to improve the commit messages to make them clearer and more descriptive before sharing your work with your team.
🎯 Goal: Learn how to edit commit messages of previous commits using Git's interactive rebase feature.
📋 What You'll Learn
Have a Git repository with at least three commits
Use Git commands to edit commit messages
Understand how to use interactive rebase safely
💡 Why This Matters
🌍 Real World
Improving commit messages helps your team understand changes clearly and keeps project history clean.
💼 Career
Editing commit messages is a common task for developers and DevOps engineers to maintain professional and readable version control history.
Progress0 / 4 steps
1
Create three commits with specific messages
Create three commits in your Git repository with these exact commit messages in order: Initial commit, Add README file, and Fix typo in README. Use git commit -m to set the messages.
Git
Hint
Use git commit -m "message" to create commits with the exact messages.
2
Start interactive rebase to edit commit messages
Run the Git command to start an interactive rebase for the last three commits using git rebase -i HEAD~3.
Git
Hint
Use git rebase -i HEAD~3 to start editing the last three commits.
3
Change commit messages to new ones in the rebase editor
In the interactive rebase editor, change the word pick to reword for all three commits to edit their messages. Save and close the editor to proceed.
Git
Hint
Change pick to reword for each commit line in the editor to edit messages.
4
Edit commit messages and verify final log
For each commit message prompt during the rebase, change the messages to these exact new messages in order: Setup project files, Add project README, and Correct README typo. After finishing, run git log --oneline and print the output.
Git
Hint
When prompted, replace each commit message with the new exact message. Then run git log --oneline to see the updated commits.
Practice
(1/5)
1. What does the command git rebase -i HEAD~3 allow you to do?
easy
A. Delete the last 3 commits permanently
B. View the commit history without changes
C. Create 3 new commits automatically
D. Interactively edit the last 3 commits, including their messages
Solution
Step 1: Understand the command purpose
git rebase -i HEAD~3 opens an interactive editor for the last 3 commits.
Step 2: Recognize the interactive editing feature
It allows changing commit messages, reordering, or squashing commits.
Final Answer:
Interactively edit the last 3 commits, including their messages -> Option D
Quick Check:
Interactive rebase edits commits [OK]
Hint: Use -i with HEAD~N to edit last N commits [OK]
Common Mistakes:
Thinking it deletes commits
Assuming it creates new commits
Confusing it with git log
2. Which line correctly changes a commit action to edit its message during an interactive rebase?
easy
A. reword abc123 Update README with new info
B. pick abc123 Fix typo in README
C. edit abc123 Add new feature
D. delete abc123 Remove unused file
Solution
Step 1: Identify the correct keyword for editing messages
In interactive rebase, reword lets you change the commit message only.
Step 2: Compare options
edit pauses for full commit changes, pick keeps commit as is, delete is invalid here.
Final Answer:
reword abc123 Update README with new info -> Option A
Quick Check:
Use 'reword' to edit message only [OK]
Hint: Change 'pick' to 'reword' to edit commit messages [OK]
Common Mistakes:
Using 'edit' when only message change is needed
Leaving 'pick' unchanged
Using invalid 'delete' keyword
3. After running git rebase -i HEAD~2 and changing the first commit's action from pick to reword, what happens next?
medium
A. Git deletes the first commit
B. Git opens an editor to change the first commit message, then continues rebase
C. Git aborts the rebase immediately
D. Git merges the two commits automatically
Solution
Step 1: Understand 'reword' effect during rebase
Changing 'pick' to 'reword' tells Git to pause and open the commit message editor for that commit.
Step 2: Follow rebase process
After editing the message, Git continues applying remaining commits automatically.
Final Answer:
Git opens an editor to change the first commit message, then continues rebase -> Option B
Quick Check:
'reword' opens message editor [OK]
Hint: Reword pauses to edit message, then continues [OK]
Common Mistakes:
Thinking rebase aborts on reword
Assuming commits get deleted
Expecting automatic merge without editing
4. You ran git rebase -i HEAD~2 and changed 'pick' to 'reword' for the second commit, but after saving, Git shows an error: error: could not apply abc123. What is the likely cause?
medium
A. You used 'reword' instead of 'edit'
B. You forgot to save the commit message editor
C. There is a conflict applying the second commit during rebase
D. The commit hash is invalid
Solution
Step 1: Understand the error message
error: could not apply abc123 means Git failed to apply that commit, usually due to conflicts.
Step 2: Relate to rebase process
During rebase, conflicts can happen if changes overlap; you must resolve them manually.
Final Answer:
There is a conflict applying the second commit during rebase -> Option C
Quick Check:
Apply error = conflict during rebase [OK]
Hint: Apply errors usually mean conflicts to resolve [OK]
Common Mistakes:
Assuming 'reword' causes error by itself
Ignoring conflict resolution step
Thinking commit hash is wrong
5. You want to edit the commit messages of the last 4 commits but keep the commit content unchanged. Which sequence of commands and actions is correct?
hard
A. Run git rebase -i HEAD~4, change all 'pick' to 'reword', save, then edit each message when prompted
B. Run git commit --amend four times in a row
C. Run git reset --soft HEAD~4 and recommit with new messages
D. Run git rebase -i HEAD~4, change 'pick' to 'edit', then change messages and contents
Solution
Step 1: Choose the right rebase command
git rebase -i HEAD~4 opens interactive rebase for last 4 commits.
Step 2: Use 'reword' to edit messages only
Changing 'pick' to 'reword' lets you edit commit messages without changing content.
Step 3: Save and edit messages when prompted
Git opens editor for each commit message in turn; you update and save them.
Final Answer:
Run git rebase -i HEAD~4, change all 'pick' to 'reword', save, then edit each message when prompted -> Option A
Quick Check:
Use 'reword' in interactive rebase for message edits only [OK]
Hint: Use 'reword' for messages, 'edit' for content changes [OK]