如何在项目提交历史记录中查找已删除的文件? [英] How to find a deleted file in the project commit history?

查看:119
本文介绍了如何在项目提交历史记录中查找已删除的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从前,我的项目中现在有一个文件,我现在希望能够得到.

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

这篇关于如何在项目提交历史记录中查找已删除的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆