LoginSignup
2
2

More than 1 year has passed since last update.

git grep で前後/上下の行を表示するオプション ( -A はAfter / -B はBefore / -C はCenter )

Last updated at Posted at 2018-08-07

Linux / Unix の grep コマンドと同じで、 git grep でも同じオプションで前後の行 (上下の行) が表示出来る。

後5行の例

$ git grep -A 5 [some_keyword]

After の A と覚えると良い

前5行の例

$ git grep -B 5 [some_keyword]

Before の B と覚えると良い

前後5行の例

$ git grep -C 5 [some_keyword]

Center の C と覚えると良い
(helpには出てこない表現だが語呂合わせで)

数字だけを渡しても良い

$ 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.
...

環境

  • git version 2.17.1

リンク

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2