简体   繁体   English

如何通过礼物库获取git commit文件的内容?

[英]How can I get the contents of a file of a git commit with the gift library?

I am using the https://github.com/notatestuser/gift library and here's what I have: 我正在使用https://github.com/notatestuser/gift库,这是我所拥有的:

gitCommit.tree().contents (err, gitTreeContents) ->
  console.log gitTreeContents

This gives me the tree contents, which is an array with objects that look like: 这给了我树的内容,它是一个包含对象的数组,如下所示:

{ repo: 
   { path: '/mygitrepo',
     bare: false,
     dot_git: '/mygitrepo/.git',
     git: 
      { [Function]
        cmd: [Function],
        streamCmd: [Function],
        list_remotes: [Function],
        refs: [Function] } },
  id: 'ed38d79b10503a4e7e68910f37f387f24dedd5fa',
  name: 'address.js',
  mode: '100644' }

So two questions. 有两个问题。 First, what is that id referring to? 首先,该id指的是什么? It's not a commit sha, so I assume it's a treeish? 它不是提交区,所以我认为它是树状的? Second, how can I see what the file looked like at that point in time? 第二,如何查看该时间点的文件?

Thanks 谢谢

  1. Yes, it's a tree-ish ID, that is sha-1 of a given filesystem object, in case of a plain file, sha-1 of its content. 是的,它是一个树状ID,即给定文件系统对象的sha-1,如果是纯文件,则为其内容的sha-1。
  2. To get an object at a given point of time, you should choose an appropriate commit first. 要在给定的时间点获取对象,应首先选择适当的提交。 Please note, that in a project there might be more than one commit at a given time with a file with a given name, because of possible branches. 请注意,在一个项目中,由于可能存在分支,因此在给定时间使用给定名称的文件可能要提交多个提交。 So you should choose a branch and then query that branch state at that time. 因此,您应该选择一个分支,然后在那个时候查询该分支状态。 And once again there might be more than one commit, because of possible merges in the branch. 而且由于分支中可能的合并,可能还会有一个以上的提交。
  3. gift is a simple wrapper over command line git. gift是命令行git的简单包装。 In command line git you should run a command like this: git cat-file blob <commit-sha-1>:</path/to/file> . 在命令行git中,您应该运行如下命令: git cat-file blob <commit-sha-1>:</path/to/file> Take a look at http://github.com/notatestuser/gift/blob/master/src/blob.coffee it seems, it does exactly what you need. 看一下http://github.com/notatestuser/gift/blob/master/src/blob.coffee,它看起来确实满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM