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オープンチャットもご利用ください。