Git:如何在项目提交历史记录中找到已删除的文件? [英] Git: How to find a deleted file in the project commit history?
问题描述
曾几何时,我的项目中有一个文件,我现在希望能够得到。
问题是:我不知道
如何找到此文件存在时的提交?
<如果您不知道确切的路径,您可以使用
> git log --all --full-history - ** / thefile。*
如果你知道文件的路径,你可以这样做:
git log --all --full-history - < ;路径到文件>
这应该显示所有分支触及该文件的提交列表。然后,你可以找到你想要的文件的版本,并显示它...
git show< SHA> - <路径到文件>
或者将它复制到您的工作副本中:
git checkout< SHA> ^ - < path-to-file>
符号符号( ^
),因为在< SHA>的时刻,结果在之前 ;
提交文件被删除,我们需要查看以前的提交以获取已删除文件的内容
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 was it at.
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>
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
这篇关于Git:如何在项目提交历史记录中找到已删除的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!