Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone a git repository from a historial point in time

Tags:

git

I'm developing a Rails app and using git. I decided to tryout a new gem, and created a git commit prior to any changes. To implement the gem involved removing some of my own code.

When I added the gem and made some other changes, I realised it would have been nice to have the earlier version of the app running, so I could compare side-by-side.

I solved the issue by rolling back git, copying the file tree and then re-applying the changes related to the new gem. That is I did the following:

$ git reset --hard HEAD
$ git clean -f -d

Is it possible to create a clone of a (local) git repository from one of the historical savepoints?

like image 548
port5432 Avatar asked Nov 03 '25 21:11

port5432


1 Answers

Assuming "historical savepoints" are equivalent to commit times, as file-specific timestamps are not recorded by default, the checkout command's syntax appears to be:

git checkout branch@{timediff}

As in git checkout master@{1 day ago}, alternatively, you can use git log to isolate your commit ID and check it out with git checkout master commitId.

like image 190
hd1 Avatar answered Nov 05 '25 14:11

hd1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!