I revert my code to previous version, now I want to revert it back to my latest version. How can I do that ? Thanks
4 Answers
You can walk back through the history of individual refs (tags, branches, checkouts) with e.g. HEAD@{1}
, the last place you checked out before this one, and you can get a nice historical table of contents with git log -g --decorate --oneline
.
William Pursell pointed out git reflog
, a much simpler command than git log, focused only on the work-history logs in .git/logs
.

- 55,082
- 5
- 77
- 137
-
@WilliamPursell can't forget what I didn't know ... this is why I reread docs, and came to answer questions here ... thanks! updating. – jthill May 11 '12 at 14:52
What do you mean by 'revert' ? git revert ?
You can use git reset --soft YOUR_SHA
to point HEAD to a specific commit. Or a simple git checkout master
to return back to the 'trunk' if you are lost in a "detached head" status...
The answer depends really on what your current status is.
if you used
git checkout <commit hash>
then your code is in a detached state, meaning it belongs to no branch. you can simply do a git checkout branch_name
to bring code to the latest revision
if you used
git reset <commit hash>
then you can clean up your changes and then
git pull
or if you remember the <commit hash>
of your latest revision,
git reset <commit hash>

- 1,866
- 17
- 32