Search code examples
gitgithubvisual-studio-codegit-commit

How to revert both local and remote git repository to a previous commit?


I want every commit after the one with hash ac9edf2 to disappear entirely from my local repository and the one on Github.

Trying to following instructions based on previous answers is like trying to study arcane magic. For each step forward I run into a new error, or make some unwanted change I did not intend because the instructions are confusing, and commands are not intuitively named.

I just want something to copy and paste into the command line so that I can rewind reality 3 hours ago (specifically, to that commit) so that neither my local harddrive or the Github website knows about the alternate universe where I made commits after ac9edf2.

And I need it to be such that after I copy and paste these commands into the command line and hit ENTER, I can resume committing via MSVSC as usual, and be able to press CTRL + G then click Publish branch as usual to upload my new commits to Github without getting any deadly fatal errors.

I don't want to become a git expert. I don't need to be concerned about any non-existent collaborators losing their work. I just want to go back in time to the commit ac9edf2. Forever.


Solution

  • On your local machine, with your master branch checked out (presumably that's what you want to fix up, right?):

    $ git reset --hard ac9edf2
    $ git push -f
    

    This answer does assume that your local branch is checked out as a tracking branch.