mirror of
https://github.com/git/git.git
synced 2024-11-25 19:04:18 +08:00
f22cc3fcbf
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: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
21 lines
290 B
Bash
Executable File
21 lines
290 B
Bash
Executable File
#!/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"
|