如何列出添加到 GIT 存储库第一次提交的所有文件?

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

当前状态: 我正在使用 git diff-tree -r HASH 列出特定提交中所有添加、修改和删除的文件。这一直有效到今天。

问题: 我想在我的第一次提交中列出所有添加的文件,但是将第一个 HASH 作为参数传递是行不通的。为什么?

主要问题: 如何获取第一次提交中添加的所有文件的列表?

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

这对我有用

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

第一次提交,如果坚持git diff-tree -r HASH,还需要一个参数,4b825dc642cb6eb9a060e54bf8d69288fbee4904.

4b825dc642cb6eb9a060e54bf8d69288fbee4904 是一棵空树。为了制作这个特殊的树对象:

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

或者更靠谱的方法:

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

现在 git diff-tree -r HASH 4b825dc642cb6eb9a060e54bf8d69288fbee4904 有效。

您可以标记此树对象以方便将来使用,并将其推送到其他存储库。

git tag void 4b825dc642cb6eb9a060e54bf8d69288fbee4904
git diff-tree -r HASH void
git push <remote> void