Git:获取所有具有模式的斑点
在 Git 中,如何查找对象数据库中包含字符串模式的所有 Blob 的 SHA-1 ID? git-grep
仅提供文件路径,而不提供 sha1 ID。
In Git, how do I find the SHA-1 IDs of all blobs in the object database that contain a string pattern? git-grep
provides only the file paths and not the sha1 IDs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:使用 Git 版本 2.7.4 根据新的测试结果进行更新
看起来我发布的解决方案仅通过引用日志。因此,如果您删除引用日志条目,则不会搜索该条目 - 即使该对象仍然存在。
因此,您必须执行以下操作:
源自: Git -如何列出数据库中的所有对象
旧解决方案:仅当对象在引用日志中时才有效
在所有本地对象中查找字符串“text”:
在所有本地对象中查找模式“pattern”本地对象:
这个将搜索所有对象,因此即使删除提交/分支它也会起作用。一旦对象从本地存储库中删除(例如通过 gc),它将不再包含在搜索中。
EDIT: Update based on new testing results using Git version 2.7.4
Looks like the solution I posted only goes through the reflog. So if you delete a reflog entry, that entry will not be searched through - even though the object still exists.
So you will have to do something like:
Derived from: Git - how to list ALL objects in the database
Old solution: Only works if object is in reflog
To find the string "text" in all local objects:
To find the pattern "pattern" in all local objects:
This will search through all objects, so it will work even if the commit/branch is deleted. Once an object is removed from the local repository (e.g. through a gc), it will no longer be included in the search.
您可以使用镐选项尝试 git 日志:
请参阅“如何查找包含给定字符串的文件的树的提交 SHA1"
You can try a git log using the pickaxe option:
See "How to find commit SHA1 of a tree containing a file containing a given string"
我执行了以下操作来确定我编写的某些代码是否永远丢失,或者可能隐藏在某些“无法访问”的提交中:
如果任何 git 对象包含
<,这将产生输出。 SEARCH_STRING>
。但是,它不会告诉您哪个对象包含它。但通过这样做,我找到了丢失的代码,并且最终能够将其找回来。I did the following to figure out if some code I'd written was lost forever, or was perhaps hidden in some "unreachable" commit:
This will produce output if any git object contains
<SEARCH_STRING>
. However, it won't tell you which object contains it. But by doing this, I found my missing code and I was eventually able to get it back.