git 克隆旧版本的 github repo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12256137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:31:32  来源:igfitidea点击:

Cloning an older version of github repo

gitgithubgit-checkout

提问by Mobie

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.gitHow 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?

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

回答by Olivier Refalo

You can always checkout any state you like by using a commit hash.

您始终可以使用提交哈希检查您喜欢的任何状态。

For instance, by looking a the log, you identified that 233ab4ef was the state you were interested in, issue a git checkout 233ab4efto checkout that state.

例如,通过查看日志,您确定 233ab4ef 是您感兴趣的状态,发出 agit checkout 233ab4ef以检查该状态。

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

实现这一目标的另一种方法是使用 git checkout @{14.days.ago}

回答by ronalchn

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

Git 不是那样设计的。克隆存储库时,您正在复制所有版本。

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.

要检查您可以检出的提交,请使用git log.

回答by TSpartanT

Also for Github.com UI,

同样对于 Github.com UI,

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

对于那些想要下载特定 Commit 的人,步骤如下:

  1. Go to "Commits"
  2. Click the "<>" icon to the right of the desired commit
  3. Select Clone or Download
  4. Download ZIP
  1. 转到“提交”
  2. 单击所需提交右侧的“<>”图标
  3. 选择克隆或下载
  4. 下载压缩包

Commits

提交

Select Commit

选择提交

Download ZIP

下载压缩包

回答by tryingToLearn

Posting this solution specifically for github.comUI.

专门为github.comUI发布此解决方案。

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

我使用的是旧版本的Keycloak,想下载源代码。在github.com 上,这是一个简单的过程:

  1. Go to releases section
  2. Download the required release.
  1. 转到发布部分
  2. 下载所需的版本。

enter image description hereenter image description here

enter image description hereenter image description here