根据日期从git检出旧提交 [英] Checkout old commit from git based on date

查看:101
本文介绍了根据日期从git检出旧提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于与另一个项目(共享此代码)不兼容,我试图从git中检索旧提交. git仓库是OpenZWave.

I am trying to retrieve an old commit from git, due to incompatibility with another project (which shares this code). The git repo is OpenZWave.

我在SO上找到了一条帖子,说要发出命令:

I found a post on SO saying to issue command:

git checkout @{14.days.ago}

但这会导致:

warning: Log for '' only goes back to Wed, 23 May 2018 08:02:05 -0400.
HEAD is now at 77a05ed... Update hs-ms100plus.xml

我不知道出了什么问题-显然有比今天更旧的提交了.此命令有什么问题? (并且该命令会导致我的克隆副本被14天前的代码替换)

I can't figure out what's wrong - clearly there are older commits than today's date. What is wrong with this command? (And will that command result in my clone being replaced with code from 14 days ago)

推荐答案

语法@{XXX.days.ago}指的是HEAD指向14天前在此存储库中,在我的计算机上的位置",而不是"14天前进行的提交"(可能是在其他存储库上进行的)另一台计算机).

The syntax @{XXX.days.ago} refers to the reflog, a local history kept by Git in addition to the history as shown by e.g. git log. So, @{14.days.ago} means "where HEAD pointed to 14 days ago on this repository, on my computer", not "the commit made 14 days ago" (which was probably made on another repository on another computer).

您可以改为:

  • 获取提交ID,例如

git log --before 14.days.ago -1

  • 签出此提交:
  • 
    git checkout 
    

    这篇关于根据日期从git检出旧提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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