git reset --hard

Discard all changes and revert to the commit specified

The git reset --hard command allows you to discard all changes and revert back to the commit specified. This command resets both the staging area (index) and working directory to match the specified commit. Any changes made after the specified commit will be permanently discarded.

Variations:

  • git reset --hard HEAD: Reset to the latest commit in the current branch
  • git reset --hard <commit>: Reset to a specific commit using its commit hash
  • git reset --hard <branch>: Reset to the latest commit in another branch
  • git reset --hard origin/master: Reset to the latest commit in the remote branch named 'master'

It is important to note that git reset --hard is a destructive command that permanently deletes changes. Make sure to use it with caution and ensure you have a backup of any important work.

Sign in to enable bookmarking, reminders, progress-tracking and more...

Sign in to enable bookmarking, reminders, progress-tracking and more...

Sign in to enable bookmarking, reminders, progress-tracking and more...