From 3ac4440801905d11de3ba585c2fe306311db6c45 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Mon, 15 Feb 2010 19:25:40 -0500 Subject: grep documentation: clarify what files match Clarify that git-grep(1) searches only tracked files, and that each is a pathspec, as in any other ordinary git commands. Add an example to show a simple use case for searching all .c and .h files in the current directory and below. Signed-off-by: Mark Lodato Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 8c700200f5..fa91e8bebd 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -22,12 +22,12 @@ SYNOPSIS [-A ] [-B ] [-C ] [-f ] [-e] [--and|--or|--not|(|)|-e ...] [...] - [--] [...] + [--] [...] DESCRIPTION ----------- -Look for specified patterns in the working tree files, blobs -registered in the index file, or given tree objects. +Look for specified patterns in the tracked files in the work tree, blobs +registered in the index file, or blobs in given tree objects. OPTIONS @@ -49,7 +49,7 @@ OPTIONS Don't match the pattern in binary files. --max-depth :: - For each pathspec given on command line, descend at most + For each given on command line, descend at most levels of directories. A negative value means no limit. -w:: @@ -163,12 +163,19 @@ OPTIONS \--:: Signals the end of options; the rest of the parameters - are limiters. + are limiters. +...:: + If given, limit the search to paths matching at least one pattern. + Both leading paths match and glob(7) patterns are supported. Example ------- +git grep 'time_t' -- '*.[ch]':: + Looks for `time_t` in all tracked .c and .h files in the working + directory and its subdirectories. + git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \):: Looks for a line that has `#define` and either `MAX_PATH` or `PATH_MAX`. -- cgit v1.2.3 From 73e9da019655261e456ed862340880de365111f0 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Tue, 16 Feb 2010 23:55:58 -0500 Subject: Add an optional argument for --color options Make git-branch, git-show-branch, git-grep, and all the diff-based programs accept an optional argument for --color. The argument is a colorbool: "always", "never", or "auto". If no argument is given, "always" is used; --no-color is an alias for --color=never. This makes the command-line interface consistent with other GNU tools, such as `ls' and `grep', and with the git-config color options. Note that, without an argument, --color and --no-color work exactly as before. To implement this, two internal changes were made: 1. Allow the first argument of git_config_colorbool() to be NULL, in which case it returns -1 if the argument isn't "always", "never", or "auto". 2. Add OPT_COLOR_FLAG(), OPT__COLOR(), and parse_opt_color_flag_cb() to the option parsing library. The callback uses git_config_colorbool(), so color.h is now a dependency of parse-options.c. Signed-off-by: Mark Lodato Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index e019e760b4..70c7ef95f6 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -18,7 +18,7 @@ SYNOPSIS [-z | --null] [-c | --count] [--all-match] [-q | --quiet] [--max-depth ] - [--color | --no-color] + [--color[=] | --no-color] [-A ] [-B ] [-C ] [-f ] [-e] [--and|--or|--not|(|)|-e ...] [...] @@ -111,12 +111,14 @@ OPTIONS Instead of showing every matched line, show the number of lines that match. ---color:: +--color[=]:: Show colored matches. + The value must be always (the default), never, or auto. --no-color:: Turn off match highlighting, even when the configuration file gives the default to color output. + Same as `--color=never`. -[ABC] :: Show `context` trailing (`A` -- after), or leading (`B` -- cgit v1.2.3 From 04416018a77ced575c35791f8300ab014417aab9 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Thu, 25 Feb 2010 22:40:10 -0500 Subject: grep docs: pluralize "Example" section Signed-off-by: Mark Lodato Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index c44724d03a..ae663b0210 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -174,8 +174,8 @@ OPTIONS If given, limit the search to paths matching at least one pattern. Both leading paths match and glob(7) patterns are supported. -Example -------- +Examples +-------- git grep 'time_t' -- '*.[ch]':: Looks for `time_t` in all tracked .c and .h files in the working -- cgit v1.2.3 From bfb8306de5382efdee20e9aef3ba6b7a3fae6a64 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Thu, 25 Feb 2010 22:40:11 -0500 Subject: grep docs: use AsciiDoc literals consistently The convention for this particular page is to use AsciiDoc literal strings only for options (`-x` or `--long`), but not for definition list terms and not for . Signed-off-by: Mark Lodato Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index ae663b0210..2e161306e4 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -98,8 +98,8 @@ OPTIONS --files-without-match:: Instead of showing every matched line, show only the names of files that contain (or do not contain) matches. - For better compatibility with 'git diff', --name-only is a - synonym for --files-with-matches. + For better compatibility with 'git diff', `--name-only` is a + synonym for `--files-with-matches`. -z:: --null:: @@ -125,7 +125,7 @@ OPTIONS matches. -:: - A shortcut for specifying -C. + A shortcut for specifying `-C`. -p:: --show-function:: @@ -140,7 +140,7 @@ OPTIONS -e:: The next parameter is the pattern. This option has to be - used for patterns starting with - and should be used in + used for patterns starting with `-` and should be used in scripts passing user input to grep. Multiple patterns are combined by 'or'. @@ -163,7 +163,7 @@ OPTIONS Do not output matched lines; instead, exit with status 0 when there is a match and with non-zero status when there isn't. -`...`:: +...:: Search blobs in the trees for specified patterns. \--:: -- cgit v1.2.3 From ec2537beda63f78746f8b43a031120be0d32310e Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Thu, 25 Feb 2010 22:40:12 -0500 Subject: grep docs: --cached and ... are incompatible In the synopsis for git-grep(1), show that --cached and ... cannot be used together. Signed-off-by: Mark Lodato Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 2e161306e4..37ce94305b 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -9,8 +9,7 @@ git-grep - Print lines matching a pattern SYNOPSIS -------- [verse] -'git grep' [--cached] - [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp] +'git grep' [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp] [-v | --invert-match] [-h|-H] [--full-name] [-E | --extended-regexp] [-G | --basic-regexp] [-F | --fixed-strings] [-n] @@ -21,7 +20,8 @@ SYNOPSIS [--color | --no-color] [-A ] [-B ] [-C ] [-f ] [-e] - [--and|--or|--not|(|)|-e ...] [...] + [--and|--or|--not|(|)|-e ...] + [--cached | ...] [--] [...] DESCRIPTION -- cgit v1.2.3 From 2e48fcdbc45eeb95b3da1cf70787ddadf62d9bf5 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Thu, 25 Feb 2010 22:40:13 -0500 Subject: grep docs: document --no-index option Also clarify --cached and . Signed-off-by: Mark Lodato Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 37ce94305b..ee506e67f0 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -21,7 +21,7 @@ SYNOPSIS [-A ] [-B ] [-C ] [-f ] [-e] [--and|--or|--not|(|)|-e ...] - [--cached | ...] + [--cached | --no-index | ...] [--] [...] DESCRIPTION @@ -33,8 +33,11 @@ registered in the index file, or blobs in given tree objects. OPTIONS ------- --cached:: - Instead of searching in the working tree files, check - the blobs registered in the index file. + Instead of searching tracked files in the working tree, search + blobs registered in the index file. + +--no-index:: + Search files in the current directory, not just those tracked by git. -a:: --text:: @@ -164,7 +167,8 @@ OPTIONS there is a match and with non-zero status when there isn't. ...:: - Search blobs in the trees for specified patterns. + Instead of searching tracked files in the working tree, search + blobs in the given trees. \--:: Signals the end of options; the rest of the parameters -- cgit v1.2.3 From 678e484b7d4e6388edeec3470bbbcd206817c148 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 12 Jun 2010 11:36:51 -0500 Subject: grep: Add the option '--open-files-in-pager' This adds an option to open the matching files in the pager, and if the pager happens to be "less" (or "vi") and there is only one grep pattern, it also jumps to the first match right away. The short option was chose as '-O' to avoid clashes with GNU grep's options (as suggested by Junio). So, 'git grep -O abc' is a short form for 'less +/abc $(grep -l abc)' except that it works also with spaces in file names, and it does not start the pager if there was no matching file. [jn: rebased and added tests; with error handling fix from Junio squashed in] Signed-off-by: Johannes Schindelin Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 4b32322a67..8fdd8e1e42 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -14,6 +14,7 @@ SYNOPSIS [-E | --extended-regexp] [-G | --basic-regexp] [-F | --fixed-strings] [-n] [-l | --files-with-matches] [-L | --files-without-match] + [-O | --open-files-in-pager] [-z | --null] [-c | --count] [--all-match] [-q | --quiet] [--max-depth ] @@ -104,6 +105,13 @@ OPTIONS For better compatibility with 'git diff', `--name-only` is a synonym for `--files-with-matches`. +-O:: +--open-files-in-pager:: + Open the matching files in the pager (not the output of 'grep'). + If the pager happens to be "less" or "vi", and the user + specified only one pattern, the first file is positioned at + the first match automatically. + -z:: --null:: Output \0 instead of the character that normally follows a -- cgit v1.2.3 From 0af88c15e2eb0a680c3797da8d8b97636b797f66 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 12 Jun 2010 11:39:46 -0500 Subject: grep -O: allow optional argument specifying the pager (or editor) Suppose you want to edit all files that contain a specific search term. Of course, you can do something totally trivial such as git grep -z -e | xargs -0r vi +/ but maybe you are happy that the same will be achieved by git grep -Ovi now. [jn: rebased and added tests] Signed-off-by: Johannes Schindelin Signed-off-by: Jonathan Nieder Acked-by: Paolo Bonzini Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 8fdd8e1e42..d89ec32485 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -14,7 +14,7 @@ SYNOPSIS [-E | --extended-regexp] [-G | --basic-regexp] [-F | --fixed-strings] [-n] [-l | --files-with-matches] [-L | --files-without-match] - [-O | --open-files-in-pager] + [(-O | --open-files-in-pager) []] [-z | --null] [-c | --count] [--all-match] [-q | --quiet] [--max-depth ] @@ -105,8 +105,8 @@ OPTIONS For better compatibility with 'git diff', `--name-only` is a synonym for `--files-with-matches`. --O:: ---open-files-in-pager:: +-O []:: +--open-files-in-pager []:: Open the matching files in the pager (not the output of 'grep'). If the pager happens to be "less" or "vi", and the user specified only one pattern, the first file is positioned at -- cgit v1.2.3 From 8b6d7924f865f29e625d0fbd3e1307af30e51908 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 25 Jun 2010 04:16:24 +0200 Subject: Documentation: grep: fix asciidoc problem with -- Asciidoc interprets two dashes separated by spaces as a single big dash. So let's escape the first dash, so that "\--" will properly appear as "--". Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 4b32322a67..912bddd7b6 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -183,7 +183,7 @@ OPTIONS Examples -------- -git grep 'time_t' -- '*.[ch]':: +git grep 'time_t' \-- '*.[ch]':: Looks for `time_t` in all tracked .c and .h files in the working directory and its subdirectories. -- cgit v1.2.3 From 3988da063611de7391f794791a4622caf47c0708 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 20 Aug 2010 05:28:53 -0500 Subject: Documentation: add missing quotes to "git grep" examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without an indication to the contrary, Asciidoc puts 'quoted text' in italics, making the output look like this: git grep time_t -- *.[ch] Looks for time_t in all tracked .c and .h files in the working directory and its subdirectories. git grep -e '#define\' --and \( -e MAX_PATH -e PATH_MAX \) Looks for a line that has #define and either MAX_PATH or PATH_MAX. In the first example, the *.[ch] argument needs to be protected from the shell, or else it will only match files in the current directory. The second example has a stray backslash. Reported-by: Frédéric Brière Cc: Mark Lodato Cc: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 5474dd7f94..dab0a78fa8 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -191,11 +191,11 @@ OPTIONS Examples -------- -git grep 'time_t' \-- '*.[ch]':: +git grep {apostrophe}time_t{apostrophe} \-- {apostrophe}*.[ch]{apostrophe}:: Looks for `time_t` in all tracked .c and .h files in the working directory and its subdirectories. -git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \):: +git grep -e {apostrophe}#define{apostrophe} --and \( -e MAX_PATH -e PATH_MAX \):: Looks for a line that has `#define` and either `MAX_PATH` or `PATH_MAX`. -- cgit v1.2.3 From 48bb914ed641fc0880d86b16cbb17c84769c320a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 11 Mar 2011 00:52:08 -0500 Subject: doc: drop author/documentation sections from most pages The point of these sections is generally to: 1. Give credit where it is due. 2. Give the reader an idea of where to ask questions or file bug reports. But they don't do a good job of either case. For (1), they are out of date and incomplete. A much more accurate answer can be gotten through shortlog or blame. For (2), the correct contact point is generally git@vger, and even if you wanted to cc the contact point, the out-of-date and incomplete fields mean you're likely sending to somebody useless. So let's drop the fields entirely from all manpages except git(1) itself. We already point people to the mailing list for bug reports there, and we can update the Authors section to give credit to the major contributors and point to shortlog and blame for more information. Each page has a "This is part of git" footer, so people can follow that to the main git manpage. --- Documentation/git-grep.txt | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index dab0a78fa8..d4d425ea30 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -203,16 +203,6 @@ git grep --all-match -e NODE -e Unexpected:: Looks for a line that has `NODE` or `Unexpected` in files that have lines that match both. -Author ------- -Originally written by Linus Torvalds , later -revamped by Junio C Hamano. - - -Documentation --------------- -Documentation by Junio C Hamano and the git-list . - GIT --- Part of the linkgit:git[1] suite -- cgit v1.2.3 From 7d6cb10b84d9931aacf1914db192cbeaaa88443d Mon Sep 17 00:00:00 2001 From: Joe Ratterman Date: Mon, 28 Mar 2011 13:11:55 -0500 Subject: grep: Add the option '--line-number' This is a synonym for the existing '-n' option, matching GNU grep. Signed-off-by: Joe Ratterman Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index dab0a78fa8..791d4d4871 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -93,6 +93,7 @@ OPTIONS as a regex). -n:: +--line-number:: Prefix the line number to matching lines. -l:: -- cgit v1.2.3 From b22520a37c8472751f2c4b3da9b5bc4e5aa5a0a3 Mon Sep 17 00:00:00 2001 From: Joe Ratterman Date: Wed, 30 Mar 2011 14:31:05 -0500 Subject: grep: allow -E and -n to be turned on by default via configuration Add two configration variables grep.extendedRegexp and grep.lineNumbers to allow the user to skip typing -E and -n on the command line, respectively. Scripts that are meant to be used by random users and/or in random repositories now have use -G and/or --no-line-number options as appropriately to override the settings in the repository or user's ~/.gitconfig settings. Just because the script didn't say "git grep -n" no longer guarantees that the output from the command will not have line numbers. Signed-off-by: Joe Ratterman Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 132505eb4f..d7523b3e45 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -31,6 +31,16 @@ Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects. +CONFIGURATION +------------- + +grep.lineNumber:: + If set to true, enable '-n' option by default. + +grep.extendedRegexp:: + If set to true, enable '--extended-regexp' option by default. + + OPTIONS ------- --cached:: -- cgit v1.2.3 From d2355d76150316104b89443065e62a71342c36be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kiedrowicz?= Date: Thu, 5 May 2011 00:00:17 +0200 Subject: Documentation: Add --line-number to git-grep synopsis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 7d6cb10b ("grep: Add the option '--line-number'", 2011-03-28) introduced the --line-number option and added its description to OPTIONS section, but forgot to update SYNOPSIS. Signed-off-by: Michał Kiedrowicz Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index d7523b3e45..4a5837881d 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -12,7 +12,7 @@ SYNOPSIS 'git grep' [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp] [-v | --invert-match] [-h|-H] [--full-name] [-E | --extended-regexp] [-G | --basic-regexp] - [-F | --fixed-strings] [-n] + [-F | --fixed-strings] [-n | --line-number] [-l | --files-with-matches] [-L | --files-without-match] [(-O | --open-files-in-pager) []] [-z | --null] -- cgit v1.2.3 From 63e7e9d8b6483fed555ebed1c79a4820b2ba2558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kiedrowicz?= Date: Mon, 9 May 2011 23:52:05 +0200 Subject: git-grep: Learn PCRE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch teaches git-grep the --perl-regexp/-P options (naming borrowed from GNU grep) in order to allow specifying PCRE regexes on the command line. PCRE has a number of features which make them more handy to use than POSIX regexes, like consistent escaping rules, extended character classes, ungreedy matching etc. git isn't build with PCRE support automatically. USE_LIBPCRE environment variable must be enabled (like `make USE_LIBPCRE=YesPlease`). Signed-off-by: Michał Kiedrowicz Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Documentation/git-grep.txt') diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 4a5837881d..e150c77cff 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -12,6 +12,7 @@ SYNOPSIS 'git grep' [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp] [-v | --invert-match] [-h|-H] [--full-name] [-E | --extended-regexp] [-G | --basic-regexp] + [-P | --perl-regexp] [-F | --fixed-strings] [-n | --line-number] [-l | --files-with-matches] [-L | --files-without-match] [(-O | --open-files-in-pager) []] @@ -97,6 +98,11 @@ OPTIONS Use POSIX extended/basic regexp for patterns. Default is to use basic regexp. +-P:: +--perl-regexp:: + Use Perl-compatible regexp for patterns. Requires libpcre to be + compiled in. + -F:: --fixed-strings:: Use fixed strings for patterns (don't interpret pattern -- cgit v1.2.3