Reverting/resetting a GIT commit

If something gets committed to a GIT repo, the following command can be run to reverse it;

$ git reset HEAD~

Eg;

$ git commit -m "Something terribly misguided" # (1)
$ git reset HEAD~ # (2)
<< edit files as necessary >> # (3)
$ git add ... # (4)
$ git commit -c ORIG_HEAD # (5)

If the commit has already been pushed to your external repo, you’ll need to add ‘–force’ next time you push if the commit is rejected (the repo is probably going to be ‘ahead’ of the commit you’re trying to push to it);

$ git push origin master --force

Ref; https://stackoverflow.com/questions/927358/how-to-undo-the-most-recent-commits-in-git

Leave a Reply