【问题标题】:How to list all files added to the first commit of a GIT repository?如何列出添加到 GIT 存储库的第一次提交的所有文件?
【发布时间】:2017-06-06 15:03:48
【问题描述】:

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

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

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

【问题讨论】:

标签: git git-commit git-diff-tree


【解决方案1】:

这对我有用

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

【讨论】:

    【解决方案2】:

    git show --pretty=format: --name-only &lt;revision&gt;

    【讨论】:

      【解决方案3】:

      对于第一次提交,如果你坚持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 有效。

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

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

      【讨论】:

      • 您不必创建空树:它始终存在。如果您不想对幻数进行硬编码,请使用git hash-object -t tree 查找其哈希值;见stackoverflow.com/q/9765453/1256452
      • @torek 很棒。谢谢!
      • 命令git hash-object -t tree 在我的情况下没有输出任何内容。根据 git 手册页,该文件是强制性参数,所以这个对我有用:git hash-object -t tree /dev/null
      猜你喜欢
      • 2010-12-14
      • 2017-04-10
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      相关资源
      最近更新 更多