Bird
Raised Fist0
Gitdevops~20 mins

Editing commit messages with rebase in Git - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

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
Challenge - 5 Problems
🎖️
Rebase Message Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of interactive rebase command
You run the command git rebase -i HEAD~3 to edit the last 3 commits. What will Git open for you?
AA merge conflict resolution tool.
BA list of all branches in the repository.
CA text editor showing the last 3 commits with options to pick, squash, or edit each commit message.
DThe commit history graph in the terminal.
Attempts:
2 left
💡 Hint
Think about what interactive rebase is used for.
🔀 Workflow
intermediate
2:00remaining
Steps to change a commit message in the middle of history
You want to change the commit message of the second last commit in your branch. Which sequence of commands correctly achieves this?
Agit rebase -i HEAD~2, then change 'pick' to 'reword' for the second commit, save and exit, then edit the message when prompted.
Bgit commit --amend on the second last commit directly.
Cgit reset --soft HEAD~2, then git commit with new message.
Dgit checkout second_last_commit, then git commit --amend.
Attempts:
2 left
💡 Hint
Amending only works on the latest commit.
Troubleshoot
advanced
2:00remaining
Error during rebase when editing commit message
You run git rebase -i HEAD~4 and change a commit message, but Git stops with the error: error: could not apply . What is the most likely cause?
AYour Git version does not support interactive rebase.
BThere is a conflict between the commit being rebased and later commits that must be resolved manually.
CThe commit message contains invalid characters.
DYou forgot to save the commit message after editing.
Attempts:
2 left
💡 Hint
Think about what happens when commits change history.
🧠 Conceptual
advanced
1:30remaining
Effect of rebase on commit hashes after editing messages
After editing a commit message using interactive rebase, what happens to the commit hash of that commit and its descendants?
AThe commit hash of the edited commit and all its descendants change because commit hashes depend on commit content.
BOnly the edited commit's hash changes; descendants keep their original hashes.
CNone of the commit hashes change because messages do not affect hashes.
DOnly the descendants' hashes change; the edited commit's hash stays the same.
Attempts:
2 left
💡 Hint
Commit hashes are based on the commit content including the message.
Best Practice
expert
2:30remaining
Best practice when rewriting commit messages on a shared branch
You need to rewrite commit messages on a branch that others have already pulled. What is the best practice to avoid problems?
ARebase and force push immediately without informing anyone.
BAvoid rewriting history; instead, add new commits that fix messages.
CDelete the remote branch and push a new branch with the rewritten history.
DCommunicate with your team, perform the rebase locally, then force push the branch with <code>git push --force-with-lease</code>.
Attempts:
2 left
💡 Hint
Think about collaboration and safety when rewriting history.

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

  1. Step 1: Understand the command purpose

    git rebase -i HEAD~3 opens an interactive editor for the last 3 commits.
  2. Step 2: Recognize the interactive editing feature

    It allows changing commit messages, reordering, or squashing commits.
  3. Final Answer:

    Interactively edit the last 3 commits, including their messages -> Option D
  4. 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

  1. Step 1: Identify the correct keyword for editing messages

    In interactive rebase, reword lets you change the commit message only.
  2. Step 2: Compare options

    edit pauses for full commit changes, pick keeps commit as is, delete is invalid here.
  3. Final Answer:

    reword abc123 Update README with new info -> Option A
  4. 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

  1. Step 1: Understand 'reword' effect during rebase

    Changing 'pick' to 'reword' tells Git to pause and open the commit message editor for that commit.
  2. Step 2: Follow rebase process

    After editing the message, Git continues applying remaining commits automatically.
  3. Final Answer:

    Git opens an editor to change the first commit message, then continues rebase -> Option B
  4. 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

  1. Step 1: Understand the error message

    error: could not apply abc123 means Git failed to apply that commit, usually due to conflicts.
  2. Step 2: Relate to rebase process

    During rebase, conflicts can happen if changes overlap; you must resolve them manually.
  3. Final Answer:

    There is a conflict applying the second commit during rebase -> Option C
  4. 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

  1. Step 1: Choose the right rebase command

    git rebase -i HEAD~4 opens interactive rebase for last 4 commits.
  2. Step 2: Use 'reword' to edit messages only

    Changing 'pick' to 'reword' lets you edit commit messages without changing content.
  3. Step 3: Save and edit messages when prompted

    Git opens editor for each commit message in turn; you update and save them.
  4. Final Answer:

    Run git rebase -i HEAD~4, change all 'pick' to 'reword', save, then edit each message when prompted -> Option A
  5. Quick Check:

    Use 'reword' in interactive rebase for message edits only [OK]
Hint: Use 'reword' for messages, 'edit' for content changes [OK]
Common Mistakes:
  • Using commit --amend repeatedly instead of rebase
  • Resetting and recommitting loses history
  • Using 'edit' when only message change needed