Lawrence
Lawrence

Reputation: 348

How to list all files added to the first commit of a GIT repository?

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?

Upvotes: 4

Views: 1782

Answers (3)

sensorario
sensorario

Reputation: 21600

This works for me

git show <commit|branch-name> --name-only

Upvotes: 4

ElpieKay
ElpieKay

Reputation: 30858

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

Upvotes: 2

Dmitriusan
Dmitriusan

Reputation: 12369

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

Upvotes: 1

Related Questions