3

I need to look at the commit i did few weeks ago e.g. when i do

> git log --oneline -10
b45e80d ten
711aa9c nine
166dbfa eight
26abb54 seven
ddd6bb6 siz
54430c3 five
ca2d76f four
81ccc8c three
d362fbc two
7d43aba one

i need to restore my site temporarily to state it was after i did this commit 81ccc8c three

How do i go about it?


Good thing i had repo pushed to bitbucket before i tried

git revert 81ccc8c

and my files did not update in project folder however it showed bunch of changes when i did git status and would not let me revert back to any other commit.

What should i do just go back to b45e80d ten

2 Answers 2

5

You want to checkout that commit:

git checkout 81ccc8c

This will update your directory to reflect the contents of that commit. You may have to stash your changes first. Afterwards, you'll be in a detached head state, and you should avoid making any commits unless you associate some branch with your current commit.

1

You can use checkout:

git checkout 81ccc8c

This will take you off your current branch and put you at the state of the commit that you use as parameter to checkout. To go back to your branch simply checkout the branch that you were on (e.g. master):

git checkout master

You don't want to use revert. That applies a new commit that undoes the commit that you pass as parameter to revert which isn't what you intended. To undo the effects of your unintended revert you should reset back to your 'ten' commit: git reset --hard b45e80d.

1
  • 1
    doh git is so complicated i was better of just copying files manually... Well i continue using git as its great tool but to dont meess up i will copy my git repo before running any commands other than stage commit and push :)
    – John Smith
    Oct 9, 2012 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.