如何 git grep 主存储库及其所有子模块? [英] How to git grep the main repository and all its submodules?

查看:27
本文介绍了如何 git grep 主存储库及其所有子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 grep 项目和子模块的博客上找到了这个:

I found this at a blog to grep project and submodules:

[alias]
  sgrep = "!f() { git grep "$1"; git submodule foreach "git grep '$1'; true" | grep -B 1 "$1"; }; f"

我更新了我的 ~/.gitconfig 以包含它,但是当我使用别名时,它说:

I updated my ~/.gitconfig to include it, but when I use the alias, it says:

fatal:/home/myname/.gitconfig 中的错误配置文件第 9 行

我做错了什么?

推荐答案

一般来说,类似于 "GitConfig: bad config for shell command",这可能是因为 '' 字符在 shell 中执行之前先被 git 解释.

Generally, similar to "GitConfig: bad config for shell command", it may be because the '' character is interpreted by git first, before being executed in a shell.

但在您的情况下,由于周围的双引号,这应该按预期工作.
它确实适用于我在 Ubuntu 上的 git 1.8.4.

But in your case, this should work as expected because of the surrounding double-quotes.
It does work on my git 1.8.4 on Ubuntu.

所以简化你的 .gitconfig 并检查如果它包含你的别名(并且没有)是否更好.
如果确实有效,那么问题出在您的配置文件中的其他地方.

So simplify your .gitconfig and check if works better if it contains your alias (and nothing) else.
If that does work, then the issue is elsewhere in your config file.

这篇关于如何 git grep 主存储库及其所有子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆