Skip to content

What is best way to revert commit? #22346

Discussion options

You must be logged in to vote

There are a bunch of different ways to revert a commit, depending on what the desired end result is. It sounds like you want to:

  1. Remove the last commit on the current branch from the repository
  2. Revert the state of the local repository to the commit prior to the commit named in item 1
  3. Update the current branch on the origin remote to the local state of the current branch

🚨 WARNING 🚨

Executing these commands will lose history (though Git does its best to make even that recoverable). Use these commands with caution.

In order to achieve items 1 and 2, you can execute:

git reset --hard HEAD^

In order to achive item 3, you can execute:

git push --force

Any time you use git push --force thou…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants