If you have committed the wrong files to Git, what command can you use to undo this last commit?

  • git reset --soft HEAD^
  • git revert HEAD
  • git reset --hard HEAD^
  • git reset HEAD^
The correct option, git reset --hard HEAD^, is also used in this scenario to completely undo the last commit along with the changes. It discards the commit and resets the branch pointer. Other options are for different use cases: preserving changes, creating a new commit to undo changes, and unstaging changes.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *