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?
- How can I merge a branch into master but continue working on the branch?
- Take last N commits of the current branch and apply them to another branch
- Add commit from git repository to GitHub
- Jenkins and GitHub webhook: HTTP 403
- Is it possible to get remote git log to gather full commit history of a repository?
- How to merge 2 branch in XCode?
2 Solutions collect form web for “How to revert to older version in git”
You are mixing up
git revert and
git reset you really throw away all those commits and you result at exactly the given commit.
git revert will actually add another commit which does exactly the opposite as the original commit, and therefore reverts that commit.
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.