简体   繁体   English

在所有提交中搜索文件内容,包括不在分支/存储中的“已放弃”提交

[英]Search file contents in all commits, including “abandoned” commits that aren't on a branch/stash

Somehow I thought I had made and committed changes to a file, but the changes no longer appear in my work tree, diffs, or log --patch output.不知何故,我以为我已经对文件进行了更改并提交了更改,但更改不再出现在我的工作树、差异或log --patch output。 I'm pretty confused, and my only guess is that they were inadvertently discarded by the Git diff algorithm during a rebase or merge operation.我很困惑,我唯一的猜测是它们在变基或合并操作期间被 Git 差异算法无意中丢弃。

I don't believe my repo has been garbage collected recently, so I would like to try and recover these changes before they are lost and I have to redo them.我不相信我的回购最近被垃圾收集了,所以我想在这些更改丢失之前尝试恢复这些更改,我必须重做它们。

How can I search through the contents of all commits for a particular string, including those "orphaned" and no longer located on a path between the root and a branch tip?如何在所有提交的内容中搜索特定字符串,包括那些“孤立”并且不再位于根和分支尖端之间的路径上的内容?

One possible solution is to use一种可能的解决方案是使用

git log -g -S <string>

This searches the full text of commits in the reflog .这会在reflog中搜索提交的全文。 You can also specify a path and most of the other typical log arguments if needed.如果需要,您还可以指定路径和大多数其他典型log arguments。

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

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