git repositoryの中で自分がこれまでに書いた差分を振り返ったり、自分が書いた範囲だけで検索したいときなどに使うワンライナーです。
git log --pretty=format:"%an %h" | grep suzuki | perl -nle 'print "git show $1" if /\b([a-f0-9]{9})\b/' | bash | less
grep
のところで自分のcommitしているときの名前を入れます。
端末上でカラフルに表示したい場合は
git log --pretty=format:"%an %h" | grep suzuki | perl -nle 'print "git show --color=always $1" if /\b([a-f0-9]{9})\b/' | bash | less -R
こんな感じで見れるはずです。
commit a2c89149042310b34583cfbaf7b2b98ca5b8fea4
Author: suzuki
Date: Fri Jul 26 12:12:49 2024 +0900
commitコメントコメントコメント...
diff --git a/src/hello.py b/src/hello.py
index b06e8ccb4..cabe8a15d 100644
--- a/src/hello.py
+++ b/src/hello.py
@@ -112,7 +112,7 @@ def hello(
...
...
...
- aaa
+ bbb
...
...
...
commit a571ee8f8cf0eec4bc7f57f35f151ca9fbb7598b
...
lessコマンドの中で検索できますので、過去に自分が書いたはずの部分がどこだったか忘れたときにこれで検索できます。