如何在 git 存储库中找到丢失的文件
How to find a file in a git repo that was lost
我们的存储库中曾经有一个文件包含一些我们需要检索的内容。日志太多,无法一一列举。所以我想我们可以 运行 一个命令来列出已创建的文件及其提交哈希。你怎么做到的?
- 列出为存储库中的每个提交创建的所有文件。
- 包括提交哈希和文件名。
然后我可以签出该提交并查看文件。或者,如果您知道如何列出具有特定文件的提交,那就更好了。该文件是 foo.md
比方说。然后我可以检查该文件的最后一次提交。
- git
中有内置cmd
git ls-files -d, --deleted show deleted files in the output
- Use git log --diff-filter=D --summary to get all the commits which have deleted files and the files deleted
git log --diff-filter=D --summary --pretty=format:"%h" --stat
它打印
5d07713
test2 | 0
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 test2
我们的存储库中曾经有一个文件包含一些我们需要检索的内容。日志太多,无法一一列举。所以我想我们可以 运行 一个命令来列出已创建的文件及其提交哈希。你怎么做到的?
- 列出为存储库中的每个提交创建的所有文件。
- 包括提交哈希和文件名。
然后我可以签出该提交并查看文件。或者,如果您知道如何列出具有特定文件的提交,那就更好了。该文件是 foo.md
比方说。然后我可以检查该文件的最后一次提交。
- git 中有内置cmd
git ls-files -d, --deleted show deleted files in the output
- Use git log --diff-filter=D --summary to get all the commits which have deleted files and the files deleted
git log --diff-filter=D --summary --pretty=format:"%h" --stat
它打印
5d07713
test2 | 0
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 test2