git:如何检索截至某个日期的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3161259/
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
git: how to retrieve all files as of a certain date
提问by c-urchin
I'm sure this can be done (?) (in clearcase it would be quite simple).
我确信这可以完成(?)(在clearcase中它会很简单)。
采纳答案by VonC
Don't forget file timestamp are not recordedin a DVCS like Git.
Only commit timestamp are there, and you can checkout easily a commit from a certain date.
不要忘记文件时间戳不会记录在像 Git 这样的 DVCS 中。
那里只有提交时间戳,您可以轻松检出某个日期的提交。
git checkout master@{1 month 2 weeks 3 days 1 hour 1 second ago}
(Note: such a checkout would give you a detached HEAD)
(注意:这样的结账会给你一个分离的 HEAD)
In ClearCase, this is easy provided you set the "preserve file time" option to true.
(if not, you actually record the checkin time of each file, which is a bit like the Git commit timestamp, except for every files)
在 ClearCase 中,这很容易,只要您将“保留文件时间”选项设置为 true。
(如果没有,你实际上记录了每个文件的checkin时间,有点像Git commit时间戳,除了每个文件)
回答by araqnid
Use git log
to determine a suitable revision to switch to, e.g.:
使用git log
来确定一个合适的修订开关,例如:
git log --since='2010-04-01' --until='2010-04-02'
This will show all the commits on 2010-04-01, so just pick the one that corresponds to the instant you want the files for, and note its commit id. Then just use git checkout COMMIT-ID
to switch the workspace to that commit. This will detach your workspace (HEAD) from the current branch, use git checkout master
to return.
这将显示 2010-04-01 上的所有提交,因此只需选择与您想要文件的时刻相对应的提交,并记下其提交 ID。然后只需用于git checkout COMMIT-ID
将工作区切换到该提交。这会将您的工作区 (HEAD) 从当前分支中分离出来,用于git checkout master
返回。
回答by Luca C.
first, you have to get the string that identify the commit:
首先,您必须获取标识提交的字符串:
git rev-list -n 1 --before="2009-07-27 13:37" origin/master
it prints the string (for instance XXXX), copy it and do this command:
它打印字符串(例如 XXXX),复制它并执行以下命令:
git checkout XXXX