Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverting to a specific commit based on commit id with Git? [duplicate]

Tags:

git

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.  ... etc ... 
  • 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?

like image 312
prosseek Avatar asked Sep 03 '10 19:09

prosseek


People also ask

Can I go back to a specific commit in git?

The git revert command allows you to undo the changes you have made to a code repository since a specific commit. Instead of deleting a commit, the git revert command identifies the changes between the current commit and a previous commit and creates a new commit to revert those changes.


1 Answers

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

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

git reset --hard c14809fa 

And if you reset --soft, it will move your HEAD to where they were , but leave your local files etc. the same:

git reset --soft c14809fa 

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.

like image 94
bwawok Avatar answered Sep 20 '22 21:09

bwawok