git 如何从历史 github 中获取提交的克隆

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7814349/
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-19 06:05:36  来源:igfitidea点击:

how do get a clone of a commit from history github

gitversion-control

提问by Alex Borsody

I want to clone, that is get all the files from a push 1 week ago onto my computer, I know the SHA, I just need a way to get those files onto a directory on my local machine. Is there a simple way to do this?

我想克隆,即将所有文件从 1 周前推送到我的计算机上,我知道 SHA,我只需要一种方法将这些文件放到我本地机器上的目录中。有没有一种简单的方法可以做到这一点?

采纳答案by Adam Dymitruk

you just use the archive after you clone:

您只需在克隆后使用存档:

git archive <sha1 you want> | tar -x -C /some/path/to/save/to

if you want to actually work on the repository, checkout the commit:

如果您想实际处理存储库,请检查提交:

git checkout <sha1 you want>

Just be careful as now you are not on any branch. You need a branch to push and pull and track your commits. So make a branch first and then check it out:

请小心,因为现在您不在任何分支上。您需要一个分支来推送、拉取和跟踪您的提交。所以先创建一个分支,然后检查一下:

git branch mywork <the sha1 you want>
git checkout mywork

or in one line:

或在一行中:

git checkout -b mybranch <sha1 you want>

回答by Phillip Kovalev

Run in the your working copy directory: git checkout <COMMIT_HASH>

在您的工作副本目录中运行: git checkout <COMMIT_HASH>