Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update my git working copy to a previous revision

Tags:

git

Is there a nice way to change my Git working copy to something a given number of commits ago.

E.g. To see 3 commits into the past, something like:

git reset HEAD - 3

The use case here is that I just want to see if the tests that are failing in the current working copy were also failing before my latest commit. I don't necessarily want to make any changes to the previous versions. I would then want to change the working copy back to the latest commit.

like image 483
KevinS Avatar asked Dec 11 '22 16:12

KevinS


2 Answers

If you simply want to look at a previous commit (without altering the state of your branch/repository), use git checkout.

git checkout HEAD~3

If you decide you want to do development off of this point, you can then branch.

git checkout -b specialFeature47

To return to the present, simply checkout the branch name you were on.

git checkout master

Be weary of the suggested git reset solutions. Those actually move your branch pointer (effectively deleting those 3 commits).

like image 161
TheBuzzSaw Avatar answered Jan 05 '23 15:01

TheBuzzSaw


Yes, that's possible:

git reset --hard HEAD~3
like image 20
Daniel Hilgarth Avatar answered Jan 05 '23 16:01

Daniel Hilgarth