Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active August 7, 2018 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YumaInaura/139dc0d1b8a1fcded5636673b011829d to your computer and use it in GitHub Desktop.
Save YumaInaura/139dc0d1b8a1fcded5636673b011829d to your computer and use it in GitHub Desktop.
How to remember git grep option -A -B -C meaning ( After / Before / Center )

How to remember git grep option -A -B -C meaning ( After / Before / Center )

git grep can show after or before line like as unix/linux grep command.

Show affter (trailing) 5 lines example

$ git grep -A 5 [some_keyword]

A is first letter of After

Show before (leading) 5 lines example

$ git grep -B 5 [some_keyword]

B is first letter of Before

Show after and before ( trainling and leading ) 5 lines example

$ git grep -C 5 [some_keyword]

C is the first letter of Center (In git command help, a keyword "Center" does not apears but i do not care)

You can pass only number as option.

$ git grep -5 [some_keyword]

git --help

...
-<num>, -C <num>, --context <num>
   Show <num> leading and trailing lines, and place a line containing
   -- between contiguous groups of matches.

-A <num>, --after-context <num>
   Show <num> trailing lines, and place a line containing -- between
   contiguous groups of matches.

-B <num>, --before-context <num>
   Show <num> leading lines, and place a line containing -- between
   contiguous groups of matches.
...

Versions

  • git version 2.17.1

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment