What is the difference between git reset --hard HEAD~1 and git revert HEAD?

Prepare for the TJR Bootcamp Test with flashcards and detailed questions. Get hints and explanations for each query. Ace your exam!

Multiple Choice

What is the difference between git reset --hard HEAD~1 and git revert HEAD?

The key idea here is how each command handles history versus the working tree. Using reset --hard HEAD~1 moves the current branch pointer back one commit and makes the index and working tree match that previous commit. The commit you moved away from is effectively removed from the branch’s history, which is a rewrite of history and can be destructive if others have based work on it.

In contrast, revert HEAD does not remove any commit. It creates a new commit that applies the inverse of what the previous commit did, so the net effect is undoing those changes while preserving the entire history. The original commit stays in the history, and the working tree reflects the result of the revert.

That’s why this option describes the behavior as “Reset changes the history and discards commits; revert creates a new commit that undoes the changes.” It captures the difference between rewriting history and recording an undo as a new commit.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy