Bird
Raised Fist0
Gitdevops~20 mins

Difference between reset and revert in Git - Practice Questions

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
🎖️
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.

Practice

(1/5)
1. What is the main difference between git reset and git revert?
easy
A. git reset creates a new commit, git revert deletes commits permanently.
B. git reset changes commit history, git revert creates a new commit to undo changes.
C. git reset only works on remote branches, git revert only on local branches.
D. git reset merges branches, git revert rebases branches.

Solution

  1. Step 1: Understand git reset behavior

    git reset moves the branch pointer and can remove commits from history locally.
  2. Step 2: Understand git revert behavior

    git revert creates a new commit that undoes the changes of a previous commit without changing history.
  3. Final Answer:

    git reset changes commit history, git revert creates a new commit to undo changes. -> Option B
  4. Quick Check:

    Reset changes history, revert adds undo commit [OK]
Hint: Reset rewinds history, revert adds undo commit [OK]
Common Mistakes:
  • Thinking revert deletes commits
  • Confusing reset with revert effects on remote
  • Believing reset creates new commits
2. Which of the following is the correct syntax to undo the last commit using git revert?
easy
A. git revert HEAD
B. git revert --hard HEAD
C. git revert HEAD~1
D. git revert --reset HEAD

Solution

  1. Step 1: Identify the commit to revert

    The last commit is referenced by HEAD.
  2. Step 2: Use correct revert syntax

    git revert HEAD creates a new commit that undoes the last commit.
  3. Final Answer:

    git revert HEAD -> Option A
  4. Quick Check:

    Revert last commit with git revert HEAD [OK]
Hint: Revert last commit with 'git revert HEAD' [OK]
Common Mistakes:
  • Using HEAD~1 to revert last commit
  • Adding invalid flags like --hard or --reset
  • Confusing revert syntax with reset
3. Given this sequence of commands:
git commit -m "Add feature A"
git commit -m "Fix bug B"
git reset --hard HEAD~1
git status
What will git status show after these commands?
medium
A. Working directory clean, last commit is "Add feature A"
B. Working directory clean, last commit is "Fix bug B"
C. Uncommitted changes from "Fix bug B" present
D. Error: reset failed

Solution

  1. Step 1: Understand the commits and reset

    Two commits made: "Add feature A" then "Fix bug B". git reset --hard HEAD~1 moves branch back one commit, removing "Fix bug B" commit and resets files.
  2. Step 2: Check status after reset

    Since reset was hard, working directory matches "Add feature A" commit, so no changes to commit.
  3. Final Answer:

    Working directory clean, last commit is "Add feature A" -> Option A
  4. Quick Check:

    Hard reset removes last commit and cleans changes [OK]
Hint: Hard reset moves HEAD and cleans working directory [OK]
Common Mistakes:
  • Thinking reset keeps last commit
  • Assuming changes remain after hard reset
  • Confusing reset with revert effects
4. You ran git reset --soft HEAD~1 but your changes disappeared from the staging area. What is the likely mistake?
medium
A. You forgot to commit after reset, so changes are lost.
B. You should have used git reset --hard to keep changes staged.
C. You should have used git revert instead to undo the commit.
D. You ran git reset --soft but expected it to keep changes staged; it only moves HEAD.

Solution

  1. Step 1: Understand git reset --soft effect

    This moves HEAD back but keeps changes staged (in index).
  2. Step 2: Identify why changes disappeared

    If changes disappeared from staging, likely a misunderstanding: --soft keeps changes staged, but if you see no changes staged, maybe you checked wrong or used wrong flag.
  3. Final Answer:

    You ran git reset --soft but expected it to keep changes staged; it only moves HEAD. -> Option D
  4. Quick Check:

    Soft reset moves HEAD, keeps staged changes [OK]
Hint: Soft reset moves HEAD, does not remove staged changes [OK]
Common Mistakes:
  • Confusing soft reset with hard reset
  • Expecting soft reset to undo commit and unstaged changes
  • Using revert when reset is intended
5. You pushed a commit to a shared repository but later found it causes issues. Which command should you use to undo the commit safely without rewriting history?
hard
A. git reset --hard HEAD~1
B. git checkout HEAD~1
C. git revert HEAD
D. git reset --soft HEAD~1

Solution

  1. Step 1: Understand the problem with shared commits

    Reset rewrites history and can cause problems if commits are already pushed and shared.
  2. Step 2: Choose safe undo method

    git revert HEAD creates a new commit that undoes the changes without rewriting history, safe for shared repos.
  3. Final Answer:

    git revert HEAD -> Option C
  4. Quick Check:

    Revert safely undoes shared commits without history rewrite [OK]
Hint: Use revert to undo shared commits safely [OK]
Common Mistakes:
  • Using reset on shared branches causing conflicts
  • Thinking checkout undoes commits
  • Using soft reset expecting safe undo