git checkout branch certain time

时间:2015-11-12 11:09:35

标签: git unix

I am searching for a single git command(if possible) to checkout files from one repository at certain time(i.e. my local branch time).

Scenario: I have checked out Branch1 at a certain time, may be 2 days back(11/12/2015 19:05). I want to checkout another branch i.e. Branch2 of 2 days back(11/12/2015 29:05 i.e. 10 minutes after Branch1 checkout time).

How can I achieve this?

Instead of date I can use unix time stamp if its easier.

If I use "git log -1 --format=%ct" it will give me the time stamp. Then I can add 10 minutes to this timestamp and use below command to checkout.

git archive --format tar --remote <HUB>:<REPO> master:`dirname <FILEPATH>` | tar -xO <FILE> > log_file.git

Can it be possible in one command?

1 个答案:

答案 0 :(得分:0)

Git将每次提交的时间存储在存储库中,但存储库中的存储不是基于更改的时间。 git存储库数据是根据更改本身构建的。

您不能依赖存储库按时间顺序将每个提交应用于存储库。例如,人们可以从不同的分支中挑选一个较旧的更改到当前分支,并且它的提交日期将保留为原始日期,但上一次提交的日期晚于这个樱桃选择日期。

现在,这只是为了解释。在您的情况下,我相信您知道如何对存储库进行更改。不过,git不会让你根据时间选择。

我建议使用git log从两天前查找提交,然后手动查看历史记录以查找十分钟后更改的内容。

当您找到感兴趣的修订版的哈希值时,请将其签入新分支,如下所示:

git checkout <hash> -b newbranch