0
0
Gitdevops~20 mins

git revert to undo a commit safely - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Revert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of git revert HEAD?
You run git revert HEAD in a repository where the last commit added a file named notes.txt. What will happen?
AThe last commit is deleted from the history permanently.
BA new commit is created that removes <code>notes.txt</code> from the project.
CThe repository resets to the commit before the last one, discarding changes.
DGit shows an error saying revert cannot be done on the HEAD commit.
Attempts:
2 left
💡 Hint
Think about how git revert works compared to git reset.
🧠 Conceptual
intermediate
2:00remaining
Why is git revert safer than git reset for undoing commits in shared repositories?
Choose the best reason why git revert is preferred over git reset when working with others.
A<code>git revert</code> creates a new commit that undoes changes, preserving history and avoiding conflicts.
B<code>git revert</code> deletes the commit from history, making the repository cleaner.
C<code>git revert</code> automatically merges branches after undoing commits.
D<code>git revert</code> rewrites all commit messages to keep them consistent.
Attempts:
2 left
💡 Hint
Think about what happens to commit history and collaboration.
🔀 Workflow
advanced
2:00remaining
Which command sequence correctly reverts a specific commit safely?
You want to undo the commit with hash abc1234 without affecting other commits. Which command sequence is correct?
Agit reset --hard abc1234
Bgit checkout abc1234 && git commit --amend
Cgit revert abc1234
Dgit revert HEAD~3
Attempts:
2 left
💡 Hint
Focus on reverting a specific commit by its hash.
Troubleshoot
advanced
2:00remaining
What error occurs if you try to revert a merge commit without special options?
You run git revert on a merge commit without any extra flags. What error message will Git show?
Awarning: merge conflicts detected but revert completed.
Bfatal: You are not currently on a branch.
Cerror: cannot revert because working directory is dirty.
Derror: commit <hash> is a merge but no -m option was given.
Attempts:
2 left
💡 Hint
Think about what Git needs to know when reverting merges.
Best Practice
expert
3:00remaining
What is the recommended way to undo a commit that has already been pushed to a shared repository?
You accidentally pushed a commit with sensitive data. What is the safest way to undo it without disrupting others?
AUse <code>git revert</code> to create a new commit that removes the sensitive data.
BUse <code>git reset --hard</code> to remove the commit and force push to overwrite history.
CUse <code>git rebase -i</code> to remove the commit and then push normally.
DDelete the remote branch and push a new one without the commit.
Attempts:
2 left
💡 Hint
Consider the impact on collaborators and history rewriting.