如何在项目提交历史记录中查找已删除的文件?
从前,我的项目中现在有一个文件,我现在希望能够得到.
Once upon a time, there was a file in my project that I would now like to be able to get.
问题是:我不知道何时删除它以及它在哪条路径上.
The problem is: I have no idea of when have I deleted it and on which path it was.
如何找到该文件的提交?
How can I locate the commits of this file when it existed?
如果您不知道可以使用的确切路径
If you do not know the exact path you may use
git log --all --full-history -- "**/thefile.*"
如果您知道文件所在的路径,则可以执行以下操作:
If you know the path the file was at, you can do this:
git log --all --full-history -- <path-to-file>
这应该显示所有接触该文件的分支中的提交列表.然后,您可以找到所需文件的版本,并使用...显示它.
This should show a list of commits in all branches which touched that file. Then, you can find the version of the file you want, and display it with...
git show <SHA> -- <path-to-file>
或通过以下方式将其还原到您的工作副本中:
Or restore it into your working copy with:
git checkout <SHA>^ -- <path-to-file>
请注意插入符号(^
),它使签出 prior 到所标识的那个,因为在<SHA>
提交时,文件已被删除,我们需要查看上一次提交以获取已删除文件的内容
Note the caret symbol (^
), which gets the checkout prior to the one identified, because at the moment of <SHA>
commit the file is deleted, we need to look at the previous commit to get the deleted file's contents