0
0
Gitdevops~20 mins

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

Choose your learning style9 modes available
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.