What does git reset --hard HEAD^ do?

What does git reset --hard HEAD^ do?

a) Resets the current branch to the previous commit and deletes all uncommitted changes
b) Deletes the last commit but keeps the changes in the working directory
c) Reverts the last commit and stages the changes
d) Moves the HEAD pointer to the first commit

Answer:

a) Resets the current branch to the previous commit and deletes all uncommitted changes

Explanation:

The git reset --hard HEAD^ command resets the current branch to the previous commit and deletes all uncommitted changes in both the working directory and staging area. It’s a forceful reset that discards all local changes.

This is useful when you want to completely undo the last commit and any modifications in the working directory, returning to a clean state.

Be careful when using this command, as it permanently deletes changes that aren’t committed.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top