tags:

views:

41

answers:

3

With 'git log', I get a list of commits that I have made so far.

commit f5c5cac0033439c17ebf905d4391dc0705dbd5f1
Author: prosseek 
Date:   Fri Sep 3 14:36:59 2010 -0500

    Added and modified the files.

commit c14809fafb08b9e96ff2879999ba8c807d10fb07
Author: prosseek 
Date:   Tue Aug 31 08:59:32 2010 -0500

    Just simple test for core.editor.

...
  • How can I revert it back to a specific commit? For example, what should I do if I want to go back to commit c14809fafb08b9e96ff2879999ba8c807d10fb07?
  • Is there any other/better way to go back to a specific commit with git? For example, can I put some label of each commit to get it back with the label?
+1  A: 

git reset c14809fafb08b9e96ff2879999ba8c807d10fb07 is what you're after...

Doches
Won't have to type the entire sha, just a little bit will work
bwawok
@bwawok: But it's faster to select and middle-click-paste than to type even an abbreviated SHA1!
Jefromi
+1  A: 

Do you want to roll back your repo to that state? Or you just want your local repo to look like that?

if you do

git reset --hard c14809fa

It will make your local code and local history be just like it was at that commit. But then if you wanted to push this to someone else who has the new history, it would fail.

if you do

git reset --soft c14809fa

It will make your local files changed to be like they were then, but leave your history etc. the same.

So what exactly do you want to do with this reset?

Edit -

You can add "tags" to your repo.. and then go back to a tag. But a tag is really just a shortcut to the sha1.

You can tag this as TAG1.. then a git reset --soft c14809fa, git reset --soft TAG1, or git reset --soft c14809fafb08b9e96ff2879999ba8c807d10fb07 would all do the same thing.

bwawok
@bwawok : I needed to roll back to that state. But it's good to know that I may have the option of 'look like that'. Thanks for letting me know. BTW, what option is the default? hard or soft?
prosseek
@prosseek the default is actually mixed. --mixedResets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action. See http://www.kernel.org/pub/software/scm/git/docs/git-reset.html
bwawok
@prosseek: If the various modes of reset are a bit confusing to you, even after reading the man page (carefully!) you could try this other question http://stackoverflow.com/questions/2530060/can-you-explain-to-me-git-reset-in-plain-english
Jefromi
A: 

if you want to force the issue, u can do :

git reset --hard c14809fafb08b9e96ff2879999ba8c807d10fb07

send you back to how ur git clone looked like at the time of the checkin

kenzaraque