3

Current status: I am using git diff-tree -r HASH to list all added, modified and deleted files in a specific commit. This worked until today.

The problem: I want to list all added files in my first commit, however passing the first HASH as a parameter doesn't work. Why?

Main question: How can I get the list of all files added in my first commit?

Lawrence
  • 309
  • 7
  • 18

3 Answers3

4

This works for me

git show <commit|branch-name> --name-only
sensorario
  • 20,262
  • 30
  • 97
  • 159
2

For the first commit, if you insist on git diff-tree -r HASH, one more parameter is needed, 4b825dc642cb6eb9a060e54bf8d69288fbee4904.

4b825dc642cb6eb9a060e54bf8d69288fbee4904 is an empty tree. In order to make this special tree object:

#inside your repo
git rm -r *
git write-tree
git reset HEAD --hard

Or a more reliable way:

#inside your repo
git init temp
cd temp
git commit --allow-empty -m 'empty tree'
cd ..
git fetch temp/ master
rm -rf temp

Now git diff-tree -r HASH 4b825dc642cb6eb9a060e54bf8d69288fbee4904 works.

You can tag this tree object for easy use in the future, and push it to other repos.

git tag void 4b825dc642cb6eb9a060e54bf8d69288fbee4904
git diff-tree -r HASH void
git push <remote> void
ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • 1
    You don't have to create the empty tree: it's always there. Use `git hash-object -t tree` to find its hash if you don't want to hard-code the magic number; see https://stackoverflow.com/q/9765453/1256452. – torek Jun 06 '17 at 15:51
  • @torek great. Thanks! – ElpieKay Jun 07 '17 at 00:39
  • The command `git hash-object -t tree` outputs nothing in my case. According to the git man page the file is mandatory parameter so this one works for me: `git hash-object -t tree /dev/null` – eNca Mar 26 '21 at 07:55
1

git show --pretty=format: --name-only <revision>

Dmitriusan
  • 11,525
  • 3
  • 38
  • 38