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

John Smith
  • 681
  • 5
  • 13
  • 30

2 Answers2

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.

Community
  • 1
  • 1
user229044
  • 232,980
  • 40
  • 330
  • 338
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.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • 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 09 '12 at 17:09