克隆旧版本的 github repo

我有一台亚马逊 EC2机器。我想在这台机器上克隆一个旧版本的 github repo。通常我使用 git 克隆 https://linktomyrepo.git如何克隆一个旧版本,比如说14天前的更新?我可以在存储库的提交历史中看到我需要的确切版本,但不知道如何将其克隆到 EC2机器上。我需要在每个提交旁边使用小 SHA 代码吗?

140930 次浏览

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}

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.

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:

  1. Go to releases section
  2. Download the required release.

enter image description here enter image description here

Also for Github.com UI,

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

  1. Go to "Commits"
  2. Click the "<>" icon to the right of the desired commit
  3. Select Clone or Download
  4. Download ZIP

Commits

Select Commit

Download ZIP

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

enter image description here

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:

enter image description here