Monday, November 7, 2022

Git - Reset or Revert pushed commits on master branch

Following are the steps to revert to a specific commit.

First get the commit hash, suppose I want to revert to 474412f. 
















Following are the commands:

git checkout main

git reset --hard 474412f

git push --force origin 474412f:main



Suppose your branch name is master then give master instead of main


When you push, you may confront with the error: Repository not found.


Then execute the following commands:


git remote remove origin

git remote add origin https://USERNAME:GENERATED_TOKEN@github.com/..REPO_PATH../REPOSITORY.git


Replace the CAPITAL text with proper text.

Then execute the push command again:

git push --force origin 474412f:main