如何在 Git 中从指定日期克隆远程 (GitHub) 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3790671/
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
How to in Git, clone a remote (GitHub) repository from a specifed date
提问by Matt Wear
I'm trying to clone a git repository from a certain date. Even if this is not possible. Is it possible to clone the git repository and then roll it back to a certain date?
我正在尝试从某个日期克隆一个 git 存储库。即使这是不可能的。是否可以克隆 git 存储库然后将其回滚到某个日期?
Example: my repository has been updated since May 2010, but I'd like to get the version from June 5th. I'd like to run the following command:
示例:我的存储库自 2010 年 5 月以来已更新,但我想从 6 月 5 日开始获取版本。我想运行以下命令:
git clone [email protected]:projectfolder -date 06-05-2010
回答by Jake Wharton
Cloning the repository will give you the entire commit history of all the source code.
克隆存储库将为您提供所有源代码的完整提交历史。
You need only scroll back through git log
and find the desired commit on your target date. Running git checkout SHA
where SHA
is the commit hash will give you the state of the source code on that date.
您只需要向后滚动git log
并在目标日期找到所需的提交。跑git checkout SHA
哪里SHA
是提交散列会给你当日的源代码的状态。
edit:
编辑:
git log --since=2010-06-05 --until=2010-06-06
will help narrow it down!
git log --since=2010-06-05 --until=2010-06-06
将有助于缩小范围!
回答by Aristotle Pagaltzis
git clone [email protected]:projectfolder
git reset --hard $(git rev-list -1 $(git rev-parse --until=2010-06-06) master)
回答by Chuck Vose
Maybe something like this:
也许是这样的:
git log --since=2010-06-05 --until=2010-06-05
git log --since=2010-06-05 --until=2010-06-05
Find one of the commit ids you like there then do a git checkout <checkout id>
在那里找到您喜欢的提交 ID 之一,然后执行 git checkout <checkout id>
回答by mkb
You can use git's revert command to revert every commit back to the date you are looking for, or you can just create a a new branch at the commit you are interested in.
您可以使用 git 的 revert 命令将每个提交恢复到您要查找的日期,或者您可以在您感兴趣的提交处创建一个新分支。
回答by svick
Consider the following commits:
考虑以下提交:
5 May (A) -- 7 May -- master (current)
5 May (B) -- 7 May /
There is no way git can figure out whether you want commit A
or B
. So, you should use git log
or gitk
to get the SHA1 of the commit from that date you want and then git checkout
it.
git 无法确定您是要 commitA
还是B
. 因此,您应该使用git log
或gitk
从您想要的那个日期开始获取提交的SHA1,然后使用git checkout
它。