0
0
Gitdevops~20 mins

Difference between reset and revert in Git - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Reset vs Revert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding git reset vs git revert

Which statement correctly describes the difference between git reset and git revert?

A<code>git reset</code> creates a new commit that undoes changes, while <code>git revert</code> deletes commits permanently from the history.
B<code>git reset</code> changes the commit history by moving the HEAD pointer, while <code>git revert</code> creates a new commit that undoes changes without altering history.
C<code>git reset</code> only works on remote branches, while <code>git revert</code> only works on local branches.
D<code>git reset</code> merges two branches, while <code>git revert</code> rebases commits onto another branch.
Attempts:
2 left
💡 Hint

Think about whether the command changes history or adds a new commit.

💻 Command Output
intermediate
1:30remaining
Output of git revert command

What is the output of running git revert HEAD in a repository?

Git
git revert HEAD
ADeletes the last commit permanently and moves HEAD to the previous commit.
BResets the working directory to the state of the last commit without creating a new commit.
CShows an error because <code>git revert</code> requires a commit hash, not HEAD.
DCreates a new commit that reverses the changes of the last commit and opens an editor for the commit message.
Attempts:
2 left
💡 Hint

Consider what git revert does to the commit history.

💻 Command Output
advanced
2:00remaining
Effect of git reset --hard on working directory

What happens to your working directory and commit history after running git reset --hard HEAD~2?

Git
git reset --hard HEAD~2
AShows an error because <code>--hard</code> cannot be used with relative commit references.
BCreates two new commits that undo the last two commits but keeps the working directory unchanged.
CMoves HEAD back two commits and resets the working directory and staging area to match that commit, discarding all changes after it.
DOnly moves HEAD back two commits but keeps the working directory and staging area as they were.
Attempts:
2 left
💡 Hint

Think about what --hard does to files and commits.

🔀 Workflow
advanced
2:00remaining
Choosing between reset and revert in a shared repository

You accidentally committed some incorrect changes and pushed them to a shared remote repository. Which approach is safer to undo those changes without disrupting other collaborators?

AUse <code>git revert</code> to create a new commit that undoes the changes, preserving history.
BUse <code>git reset --hard</code> locally and force push to overwrite the remote history.
CDelete the repository and create a new one without those changes.
DUse <code>git reset --soft</code> to undo the commit and push normally.
Attempts:
2 left
💡 Hint

Consider the impact on collaborators and history rewriting.

Troubleshoot
expert
2:30remaining
Troubleshooting unexpected file changes after git reset

After running git reset --mixed HEAD~1, you notice some files in your working directory have unexpected changes. Why does this happen?

A<code>--mixed</code> resets the staging area but leaves the working directory unchanged, so changes remain in files.
B<code>--mixed</code> resets both staging area and working directory, so files should be clean.
C<code>git reset --mixed</code> deletes untracked files causing unexpected changes.
D<code>--mixed</code> only affects remote branches, not local files.
Attempts:
2 left
💡 Hint

Recall the difference between --soft, --mixed, and --hard options.