0

I have the following command:

git archive HEAD | tar -xC GitPulls/

This gets everything from HEAD and places it in the previously empty /GitPulls/ folder. The folder now contains many different files - say 1000 files.

I want to get a flat text list of exactly these 1000 files with no repetition -- that is, I want a list of files that git archive HEAD | tar -xC GitPulls/ will place in the /GitPulls/ folder.

I tried git log --name-only. However, this provides output that repeats the same file multiple times -- presumably for each time that the file was modified and staged and committed.

How would this change if I wanted only the contents of a specific previous commit and not the HEAD? That is, how can I obtain the unique list of files that would be unzipped into the /GitPulls/ folder on running the following: git archive <SHAID> | tar -xC GitPulls/?

Tryer
  • 3,580
  • 1
  • 26
  • 49

1 Answers1

3

This command should do:

git ls-tree -r --name-only <commit-id>
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Ah, this is very useful. I had previously tried git ls-tree HEAD (without the -r) and was surprised at the low number of entries returned. So, recursive -r does it. – Tryer Oct 14 '22 at 08:35
  • Is it fair to say that the unique entries of `git log --name-only` should correspond to the list returned by `git ls-tree -r HEAD`? – Tryer Oct 14 '22 at 08:36
  • 1
    @Tryer: `git log --name-only` will also list files that were previously commited and are gone in the current commit. `git ls-tree` will only list files that are currently present. That's because `git log` acts on the whole history (the current and previous commits) and `git ls-tree` only looks at the specified commit/tree (the current one in this example). – Joachim Sauer Oct 14 '22 at 08:41
  • 1
    That's not fair to say. `git log` is expected to show what is changed from the previous commit (I definitely want to see _only_ the list of changed files when looking at log.... don't want to get the same full list of files in log for every commit... then I wouldn't even know what files were changed), whereas you want the full listing of a commit.... so it has to be done some other way. – eftshift0 Oct 14 '22 at 08:44
  • @eftshift0 Is it possible to list which was the last commit that updated a particular file in question? For instance, `git ls-tree -r --someotheroption HEAD | grep interested_file` ? In looking at https://git-scm.com/docs/git-ls-tree it is not clear to me how to find the most recent commit that updated the `interested_file` in the example above. – Tryer Oct 14 '22 at 08:53
  • 2
    You can run log on the file and it will list commits where it was modified... if you use `-n 1` it will list _the last_ commit where it was modified. – eftshift0 Oct 14 '22 at 08:56