【问题标题】:git: How to find file history from blob ID [duplicate]git:如何从 blob ID 中查找文件历史记录 [重复]
【发布时间】:2017-07-02 23:26:55
【问题描述】:

我正在尝试使用 git 复制 Subversion 的 $Id: $ 功能。我知道我可以使用.gitattributes 设置ident 属性,这将允许我将blob ID 嵌入源代码注释中。这是基本要求,我已经满足了。

但我正在努力研究如何使 ID 在实际意义上有用。 git loggit blame 需要文件名,所以我不能对它们使用 ID。 git show 只显示 blob 内容,但不提供任何提交链接。

我想要的是,给定一个 blob ID,以获取创建该 blob 的提交。 (最终,获取文件的git loggit blame 数据,或者能够检出包含该文件的修订版)。

我很欣赏像 git 这样的分布式系统中的提交历史比颠覆更复杂,但如果我能得到任何东西作为起点,那就足够了。我真正需要的是能够证明给定源代码,我可以追溯版本控制历史。

【问题讨论】:

标签: git svn git-log git-blame


【解决方案1】:

git tag 命令呢?检查此链接作为起点:

https://git-scm.com/book/en/v2/Git-Basics-Tagging

【讨论】:

    【解决方案2】:

    除了 blob id 之外,gitattributes 手册还描述了一个 export-subst 过滤器,因此您可以打开它并使用 $Format:%H$ 添加提交哈希,或使用 $Format:%d$ 包含分支/标签名称。您必须使用git archive 发布文件。

    例如:

    $ cat .gitattributes
    * export-subst ident
    $ cat foo.c
    // Blob hash: $Id$
    // Commit hash: $Format:%H%d$
    $ git archive master | tar -xO
    * export-subst ident
    // Blob hash: $Id: 9e0569a55a4eaacdf8d100a2c3d3654cf767650b $
    // Commit hash: 3802b7884faf182ce0994ac9d94925dad375be05 (HEAD -> master, tag: v2)
    

    【讨论】:

      猜你喜欢
      • 2019-05-05
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-10
      • 2014-06-19
      相关资源
      最近更新 更多