Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

going back to previous commit without destroying the current one

Tags:

git

So I wanted to go back to my previous commit without destryoing the latest one I have now. How do I do this? Doing a git reset HARD will destroy my current commit right?

like image 982
xonegirlz Avatar asked Jan 31 '12 23:01

xonegirlz


2 Answers

Assuming you don't have any changes that you have not checked in, git checkout $OLD_COMMIT will take you there, and git checkout $BRANCH will take you back.

That will put you, potentially, on a detached head; see git checkout --help for the details, but if all you want is to run tests on the old version or something that should be fine.

You might also be interested in: git stash - to store away uncommitted changes temporarily git show $SHA1 to show the changes of the old commit as a diff git show ${REF}:${PATH} to show the content of $PATH in $REF

(Ref can be a sha, or a branch, or whatever, in the last git show invocation.)

like image 104
Daniel Pittman Avatar answered Sep 23 '22 06:09

Daniel Pittman


Use git revert. This allows you to undo a specific commit without upsetting commits since.

If I understand your case correctly, you have:

* abc123de a_good_commit
* bc123def a_bad_commit
* c123def4 another_good_commit

You can either git revert HEAD^ or use a specific hash: git revert bc123def.

like image 25
Justin ᚅᚔᚈᚄᚒᚔ Avatar answered Sep 22 '22 06:09

Justin ᚅᚔᚈᚄᚒᚔ