1

I am using the https://github.com/notatestuser/gift library and here's what I have:

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? 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

Shamoon
  • 41,293
  • 91
  • 306
  • 570
  • Yes, it's a tree-ish, that is sha-1 of a given filesystem object, in case of a plain file, sha-1 of its content. – user3159253 Nov 21 '14 at 18:52
  • To get an object at a given point of time, you should choose an appropriate commit first. Please note, that there could be more than one file with a given name at a given time, because of branching. So you should choose a branch and then query that branch state at that time. And here again may be more than one commit, because of merging. – user3159253 Nov 21 '14 at 18:57
  • I have the commit. The `sha` of the commit is stored with `gitCommit`. How do I use that to get the contents of the file? – Shamoon Nov 21 '14 at 19:00
  • Well, I'm not familiar with the `gift` library, but believe it's a simple wrapper over command line `git`. In command line git you should run a command like this: `git cat-file blob :` – user3159253 Nov 21 '14 at 19:08
  • 1
    Take a look at https://github.com/notatestuser/gift/blob/master/src/blob.coffee it seems, it does exactly what you need – user3159253 Nov 21 '14 at 19:09

1 Answers1

2
  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.
  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. In command line git you should run a command like this: 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.
user3159253
  • 16,836
  • 3
  • 30
  • 56