How to revert to older version in git

On github we are at commit 57d7cb274622f86e586c2595317264f23626e6c5
I want to revert to commit 5798ee7c56efd7e898d3115da6efe3d5e7cddb6c which is several commits before the latest one. Here is what I am doing:

$ git fetch origin
$ git reset --hard origin/master
Head is now at  57d7cb274
$ git status
nothing to commit (working directory clean)
$git revert 5798ee7c56efd7e898d3115da6efe3d5e7cddb6c
#On branch master
nothing to commit (working directory clean)
$ git status
#On branch master
nothing to commit (working directory clean)

But the resulting code is not really at the commit at 5798ee7c56efd7e898d3115da6efe3d5e7cddb6c
What am I missing?

  • devtools/GitHub download error
  • How to maintain two versions of a project on GitHub?
  • AWS CodeDeploy can't find github tar link for private repository “could not download bundle”
  • push my changes made in gerrit to github repository
  • Github Branches are always ahead or behind
  • “An internal error occurred” when trying to commit to git from eGit in Eclipse
  • How to pull a pull request quickly locally
  • Github branch can't seem to rebase
  • 2 Solutions collect form web for “How to revert to older version in git”

    You are mixing up git revert and git reset.

    With git reset you really throw away all those commits and you result at exactly the given commit.

    But git revert will actually add another commit which does exactly the opposite as the original commit, and therefore reverts that commit.

    Using git reset is fine for your local repository, but once you pushed your commits other people might already started using those commits for their own work. Therefore you want an explicit revert commit in this case.

    Be aware that you need to revert each unneeded commit if you want to go the revert way.

    According to the documentation for git at https://www.kernel.org/pub/software/scm/git/docs/git-revert.html, git revert creates commits which reverse the specified commit.

    Therefore, the reason git status says there is nothing to commit after running git revert is that the changes you are looking for were already committed.

    I think what you are trying to achieve is done, but your test to see if it worked is flawed.

    Git Baby is a git and github fan, let's start git clone.