简体   繁体   English

如何在所有git提交中搜索一个短语?

[英]How to search for a phrase into all git commits ?

I need to search a word in all files of my repository and in all version of all files. 我需要在我的存储库的所有文件和所有版本的文件中搜索一个单词。 This because I don't know when, but there is no more a piece of code in one of my file and I want to know when was deleted and recover it. 这是因为我不知道什么时候,但我的一个文件中没有更多的代码,我想知道什么时候被删除并恢复它。

I don't know if this was what you meant, but if you want to find all commits where commit message contains given word, use 我不知道这是不是你的意思,但如果你想找到提交消息包含给定单词的所有提交,请使用

$ git log --grep=word

If you want to find all commits where "word" was added or removed in the file contents (to be more exact: where number of occurences of "word" changed), ie search the commit contents, use so called 'pickaxe' search with 如果你想找到所有在文件内容中添加或删除“word”的提交(更确切地说:“word”的出现次数发生变化),即搜索提交内容,使用所谓的'pickaxe'搜索

$ git log -Sword

Good Luck :) 祝好运 :)

What you're looking to do here is grep ( documentation on git-grep ) through the history of all revisions in the repository: 你在这里要做的是grep( 关于git-grep的文档 )通过存储库中所有修订的历史记录:

$ git grep <your_search_term> $(git rev-list --all)

Where <your_search_term> is a regex pattern. 其中<your_search_term>是正则表达式模式。

The output will include all of the commits including your found text/expression. 输出将包括所有提交,包括您找到的文本/表达式。

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

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