提交 f22cc3fc 编写于 作者: L Linus Torvalds 提交者: Junio C Hamano

[PATCH] Add "git grep" helper

Very convenient shorthand for

	git-ls-files [file-patterns] | xargs grep <pattern>

which I tend to do all the time.

Yes, it's trivial, but it's really nice. I can do

	git grep '\<some_variable\>' arch/i386 include/asm-i386

and it does exactly what you'd think it does. And since it just uses the
normal git-ls-files file patterns, you can do things like

	git grep something 'include/*.h'

and it will search all header files under the include/ subdirectory.
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
Signed-off-by: NJunio C Hamano <junkio@cox.net>
上级 ba8a4970
......@@ -76,7 +76,7 @@ SCRIPT_SH = \
git-tag.sh git-verify-tag.sh git-whatchanged.sh git.sh \
git-applymbox.sh git-applypatch.sh \
git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
git-merge-resolve.sh
git-merge-resolve.sh git-grep.sh
SCRIPT_PERL = \
git-archimport.perl git-cvsimport.perl git-relink.perl \
......
#!/bin/sh
flags=
while :; do
pattern="$1"
case "$pattern" in
-i|-I|-a|-E|-H|-h|-l)
flags="$flags $pattern"
shift
;;
-*)
echo "unknown flag $pattern" >&2
exit 1
;;
*)
break
;;
esac
done
shift
git-ls-files -z "$@" | xargs -0 grep $flags "$pattern"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册