简体   繁体   English

恢复git上删除分支时删除的文件

[英]Restore files on git that were deleted when a branch was deleted

I know there are a lot of similar questions on SO about this topic, so I apologize if this is a duplicate. 我知道关于此主题有很多类似的问题,因此,如果这是重复的,我深表歉意。 However, I think this case is unique compared to the others I've seen. 但是,我认为这种情况与我见过的其他情况相比是独一无二的。

I had some local files in my repo directory which I did not realize were untracked. 我的回购目录中有一些本地文件,但我没有意识到它们是未跟踪的。 I then created a new local branch, made a significant change to the directory structure, and did a git add of the entire directory and committed (this was the most convenient way I could think of to commit the restructure). 然后,我创建了一个新的本地分支,对目录结构进行了重大更改,并对整个目录进行了git add并提交(这是我想到的提交重组的最便捷方法)。

I later changed my mind about the restructure, so I deleted the entire branch without merging it, but this unfortunately deleted all the previously untracked files which weren't present in any of the other branches. 后来我改变了主意,因此我删除了整个分支而不合并它,但是不幸的是,这删除了所有其他分支中没有的所有先前未跟踪的文件。

I was able to find commits from the deleted branch and check them out, but the deleted files are nowhere to be found. 我能够从已删除的分支中找到提交并将其检出,但找不到删除的文件。 I've also tried using: 我也尝试过使用:

 git log -- <filepath>

Unfortunately that's not showing anything either. 不幸的是,这也没有显示任何东西。 These files were definitely deleted when the branch was deleted, so they must have been tracked by git at some point, but I can't find anything at all. 这些文件肯定是在删除分支时删除的,因此它们一定在某些时候已经被git跟踪,但是我什么也找不到。

If the file was truly committed, and your reflog was not deleted (by default - 30 days), you should be able to see which commits affected a particular set of files or directories by one the following: 如果文件是真正提交的,并且没有删除您的引用日志(默认情况下为30天),那么您应该能够通过以下方式查看哪些提交影响了一组特定的文件或目录:

git reflog -- path/to/some/file.txt
git reflog -- path/to/some/file.txt path/to/another/file.txt
git reflog -- path/to/some/directory
git reflog -- */some.file 

If it does not show up, then it means that it was never added to a commit. 如果未显示,则表示它从未添加到提交中。

If it was possibly stashed, then the following command can help: 如果可能被藏起来,则以下命令可以提供帮助:

git stash list -- path/to/some/file.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM