How to revert my remote git repository back to a certain commit?

I accidently ran:

git push origin +master

while trying to push a file to my Github repo. This command reset all the commit history and deleted a few files.

  • How to remove unwanted commit and merge
  • How to determine if a remote git repo is “safe” to pull from
  • What's the bzr equivalent to git clone --depth HEAD
  • Getting GitHub and Gerrit to play nicely
  • How to push my update changes to the repository
  • Why can I not commit? (Your branch is up-to-date with 'origin/master', no changes added to commit)
  • I was wondering if there is a way to reset my repo to a certain commit having the hash 94b90dc1121ce477131fa60ffdc234591554b6c8.

  • How can I check if a filename in my Maven project contains certain characters (and then fail the build)?
  • How to see code changes after git pull?
  • Git three-way merge: A single line is changed in branch one, & not in branch two. Why does the changed line trump the unchanged line?
  • using Git and pushing to production mode (w/ diagram)
  • Always use local version of file when git merging (even if there are no changes on one side of the merge)
  • What is the fastest way to clone a git repository over a fast network connection?
  • 2 Solutions collect form web for “How to revert my remote git repository back to a certain commit?”

    git checkout master
    git reset --hard 94b90dc1121ce477131fa60ffdc234591554b6c8
    git push -f origin master

    Here’s an explanation of the commmands…

    First, let’s make sure you are on the master branch, so use the checkout command so your HEAD points to master.

    What is HEAD?
    It’s basically the pointer that Git maintains to point to where you currently are in the Git tree.

    In fact, most of these concepts like HEAD, and branches, are just pointers to different points in the tree.
    Do a gitk from the command line to see the tree in a nice graphical format.

    Next, let’s reset your HEAD pointer to that exact commit that you had in your original question. This will basically make the files on your file-system match that commit.

    Be careful will reset --hard though…if you have outstanding work, or commit’s that are not-yet pushed to the server this may make them “unreachable” (think about that tree again)…if you “lose” commits from this command you can usually get them back by using the reflog though.

    Finally, push the local state of your master branch to GitHub’s master branch. The -f is there because you are re-writing the history of the branch, so you need to tell Git to “force” it.

    Jonathan’s answer is correct. An alternative way to achieve the same is:

    git push -f origin 94b90dc1121ce477131fa60ffdc234591554b6c8:master
    Git Baby is a git and github fan, let's start git clone.