如何按日期在Git中结帐? [英] How to checkout in Git by date?

查看:96
本文介绍了如何按日期在Git中结帐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究源代码中的回归。我想告诉Git:根据参数化日期/时间检出源。这可能吗?



我在当前的观点中也发生了变化,我不想失去。理想情况下,我希望在当前源和我感兴趣的某个版本之间根据以前的日期来回切换。

解决方案

保持你的当前变化



你可以保留你的工作,而不用提交它,用 git stash 。你
会比使用 git stash pop 找回来。或者,您可以(如 carleeto 所说) git commit 它到一个单独的分支。



使用rev-parse按日期签出



您可以使用 rev-parse 来检出特定日期的提交这:

  git checkout'master @ {1979-02-26 18:30:00}'
code>

有关可用选项的更多详细信息,请参阅 git-rev-parse

如注释中所述,此方法使用reflog在您的历史记录中查找提交。默认情况下,这些条目 90天后过期。尽管使用reflog的语法不够详细,但您只能返回90天。



使用rev-list按日期结帐



另一个不使用reflog的选项是使用 rev-list 来获取特定点的提交时间:

  git checkout`git rev-list -n 1 --before =2009-07-27 13:37 master` 


I am working on a regression in the source code. I'd like to tell Git: "checkout the source based on a parameterized date/time". Is this possible?

I also have staged changes in my current view that I don't want to lose. Ideally, I would like to toggle back and forth between the current source, and some version I'm interested in based on a previous date.

解决方案

To keep your current changes

You can keep your work stashed away, without commiting it, with git stash. You would than use git stash pop to get it back. Or you can (as carleeto said) git commit it to a separate branch.

Checkout by date using rev-parse

You can checkout a commit by a specific date using rev-parse like this:

git checkout 'master@{1979-02-26 18:30:00}'

More details on the available options can be found in the git-rev-parse.

As noted in the comments this method uses the reflog to find the commit in your history. By default these entries expire after 90 days. Although the syntax for using the reflog is less verbose you can only go back 90 days.

Checkout out by date using rev-list

The other option, which doesn't use the reflog, is to use rev-list to get the commit at a particular point in time with:

git checkout `git rev-list -n 1 --before="2009-07-27 13:37" master`

这篇关于如何按日期在Git中结帐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆