![](/img/trans.png)
[英]Accidentally created a file in Git Bash with touch that can't be deleted, modified, read, or moved (Windows 10). How do I get rid of it?
[英]can I get the object file id for a deleted file with git?
如果我运行:
git log --diff-filter=D --summary | grep delete
我可以在 repo 中获取所有已删除文件的列表,但它实际上并没有给我这些文件的 object id。
I want to be able to run git cat-file on the actual deleted file object in.git/object/ Is there a way to get a list of object ids for deleted files so I can git cat-file them?
我不想实际恢复文件来查看它。
一旦你有了删除文件的提交的sha1
,你就可以在这个提交的父文件中找到文件的内容。
# if 'sha1' points at the commit, 'sha1~' will point at its parent
git show sha1~
您真的不需要文件的 hash、 git show
或git cat-file
都了解如何通过路径导航提交的内容:
# to view the content of the file :
git show sha1~:path/to/dir/file
git cat-file -p sha1~:path/to/dir/file
# if you want to see the hash of the file :
git ls-tree sha1~:path/to/dir
git cat-file -p sha1~:path/to/dir
[编辑]
根据您的评论:您找到的sha1
似乎不是删除您正在检查的文件的提交。
要确认这一点,请运行:
git show --name-status sha1
如果您的意图是找到删除文件path/to/file
的提交,我建议使用以下git log
命令:
git log --name-status -- path/to/file
# you should quickly spot the commits which display :
D path/to/file
--graph
通常对于理解历史非常有用,-- --oneline
提供的视图类似于图形查看器所做的。 您可以尝试以下两种方式亲自查看:
git log --graph --name-status -- path/to/file
git log --graph --oneline --name-status -- path/to/file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.