ChatGPT解决这个技术问题 Extra ChatGPT

Cloning an older version of github repo

I have an Amazon EC2 machine. I would like to clone an older version of github repo on this machine. Normally I use git clone https://linktomyrepo.git How can I clone an older version, say an update from 14 days ago? I can see the exact version I need in the commit history of repository, but do not know how to clone it onto the EC2 machine. Do I need to use the little SHA code next to each commit?


O
Olivier Refalo

You can always check out any given state by using a commit hash.

For instance, by looking at the log, you identified that 233ab4ef was the state you were interested in: issue a git checkout 233ab4ef to check out that state.

Another way to achieve this is by using git checkout @{14.days.ago}


what's 14 in git checkout @{14.days.ago} exactly ?
It looks like the number of days ago that you're looking to clone. Apologies if that's not what you were asking. This says "Clone the repo based on what it looked like 14 days ago from today" if I read this right.
And about "contibue my project from this older version"? Can I do changes and "restart commits" from it?
r
ronalchn

Git is not designed that way. When you clone a repository, you are copying all versions.

So first clone a repository (which does initially checkout the latest version), then checkout the version you actually want.

You can checkout the commit based on the hash.

git checkout afe52

You can also checkout based on date (instead of looking up the hash), eg:

git checkout 'master@{1979-02-26 18:30:00}'
git checkout @{14.days.ago}

To check the commits you can checkout, use git log.


What if there are thousands of commits? What's the fastest way to see all the tagged releases? Say for things like version 1, 2, 3, etc.
@anon58192932 to view all the tags you can use git tag and to view the details of that specific tag, you can use git cat-file tag TAG_NAME for example I could use git cat-file tag v4.4.7 in the node repo to give me show me the commit string 0974fc6a25c343744235331eb20d31f6412ff7e1. :)
T
TSpartanT

Also for Github.com UI,

For those wanting to download a specific Commit, steps are below:

Go to "Commits" Click the "<>" icon to the right of the desired commit Select Clone or Download Download ZIP

Commits

Select Commit

Download ZIP


This is helpful! I don't know how I missed this, but spent a solid 15mins trying to figure out how to download an older state copy of the repo as a standalone zip. Perfect, thank you!
t
tryingToLearn

Posting this solution specifically for github.com UI.

I was using an older version of Keycloak and wanted to download the source. On github.com, it was a simple process:

Go to releases section Download the required release.

https://i.stack.imgur.com/BSn6p.png


E
ESP32

Old version on Github usually means an old branch. For example:

https://i.stack.imgur.com/LLyW4.png

In this case you can check out the old branch by using its branch name:

git clone --branch <branchname> <remote-repo-url>

The you can get here:

https://i.stack.imgur.com/7Hkbu.png