0

I revert my code to previous version, now I want to revert it back to my latest version. How can I do that ? Thanks

zjffdu
  • 25,496
  • 45
  • 109
  • 159

4 Answers4

1

Try the following:

git checkout master

(or what did You mean by revert?)

Adobe
  • 12,967
  • 10
  • 85
  • 126
1

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.

jthill
  • 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
1

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.

kostix
  • 51,517
  • 14
  • 93
  • 176
Yanflea
  • 3,876
  • 1
  • 14
  • 14
0

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>

Rahul
  • 1,866
  • 17
  • 32