Git 搜索所有差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11068145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git search all diffs
提问by patthoyts
I'm trying to search for changes in my git history relating to a very specific variable name.
我正在尝试在我的 git 历史记录中搜索与非常具体的变量名称相关的更改。
I've tried doing this:
我试过这样做:
git diff HEAD~25000 | grep -in mydistinctvariablename
The results don't tell me which commit the result lines are from and it takes quite a bit of time (about 5-7 minutes).
结果并没有告诉我结果行来自哪个提交,这需要相当长的时间(大约 5-7 分钟)。
Does anyone have a better solution, time and results wise?
有没有人有更好的解决方案、时间和结果?
回答by patthoyts
git logis generally the command to use when examining commit history. git log --grep
can be used to search for regular expressions in the commit message.
git log通常是检查提交历史时使用的命令。git log --grep
可用于在提交消息中搜索正则表达式。
What you are after is git log -S
which searches the commit content simply or git log -G
which searches it with a regular expression:
您所追求的是git log -S
简单地搜索提交内容或git log -G
使用正则表达式搜索它:
-S Look for differences that introduce or remove an instance of . Note that this is different than the string simply appearing in diff output; see the pickaxe entry in gitdiffcore(7) for more details.
-S 查找引入或删除 . 请注意,这与仅出现在 diff 输出中的字符串不同;有关更多详细信息,请参阅 gitdiffcore(7) 中的镐条目。
So, for instance, in the msysGit repository I can find the commit that introduced Tcl 8.5.8 using either:
因此,例如,在 msysGit 存储库中,我可以使用以下任一方法找到引入 Tcl 8.5.8 的提交:
C:\src\msysgit\src>git log --oneline --grep "8\.5\.8"
d938476 Make `NO_SFX=1 portable-release.sh` work
ef1dc94 Update tk to version 8.5.8
a910049 Update tcl to version 8.5.8
a702d7f tcltk: update to 8.5.8 and exclude release.sh from the cleanup list
which just looked for 8.5.8 in the commit messages or as you want to do looking at a string that only occurred in the committed diff:
它只是在提交消息中查找 8.5.8 或者您想查看仅出现在已提交差异中的字符串:
C:\src\msysgit\src>git log --oneline -S"version=8.5.8"
7be8622 tcltk: update release.sh script for tcl/tk 8.5.9
a702d7f tcltk: update to 8.5.8 and exclude release.sh from the cleanup list
The range limiting you have in your sample can still be used here to limit the commits to be examined. Read though the git log manual carefully to get a good idea of all the things it can do.
您在示例中的范围限制仍然可以在这里使用来限制要检查的提交。仔细阅读 git log 手册以了解它可以做的所有事情。
Note that -S
just looks for simple string differences - if you really want to search the content using a regular expression similar to you example then you should use the -G
option instead of -S
but this will be significantly slower.
请注意,-S
仅查找简单的字符串差异 - 如果您真的想使用类似于示例的正则表达式搜索内容,那么您应该使用该-G
选项而不是,-S
但这会显着变慢。