4
3

【Git】blameでバグの犯人探しをする

Posted at

はじめに

小ネタです。犯人探しをしたいときにお使いください。

犯人探し

git blame -n ファイル名で該当ファイルに絞って検索する事ができます。
-nは行数を表示させるコマンドです。

git blame -n index.html
^f541b32  1 (username 2023-12-20 19:15:14 +0900  1) <!DOCTYPE html>
^f541b32  2 (username 2023-12-20 19:15:14 +0900  2) <html lang="en">
^f541b32  3 (username 2023-12-20 19:15:14 +0900  3) <head>
^f541b32  4 (username 2023-12-20 19:15:14 +0900  4)     <meta charset="UTF-8">
^f541b32  5 (username 2023-12-20 19:15:14 +0900  5)     <meta name="viewport" content="width=device-width, initial-scale=1.0">
^f541b32  6 (username 2023-12-20 19:15:14 +0900  6)     <title>Document</title>
^f541b32  7 (username 2023-12-20 19:15:14 +0900  7) </head>
^f541b32  8 (username 2023-12-20 19:15:14 +0900  8) <body>
^f541b32  9 (username 2023-12-20 19:15:14 +0900  9)     <div>追加</div>
abc8c358 10 (username 2023-12-20 19:15:26 +0900 10)     <div>追加2</div>
db27514b 11 (username 2023-12-20 19:15:43 +0900 11)     <div>バグ</div>
17413c9f 12 (username 2023-12-20 19:16:01 +0900 12)     <div>追加3</div>
^f541b32 10 (username 2023-12-20 19:15:14 +0900 13) </body>
^f541b32 11 (username 2023-12-20 19:15:14 +0900 14) </html>

下記の情報が得られます。完璧ですね

  • コミットのハッシュ値
  • 変更者名
  • コミット日時

該当のコードがわかっていれば、git log -S 文字列 ファイル名でもいけるっぽいです。

git log -S "バグ" index.html

commit db27514bd2c251ed4a64326df69c54cc9f7f521f
Author: username <hogehohe@gmail.com>
Date:   Wed Dec 20 19:15:43 2023 +0900

    bugs

ハッシュ値がわかれば、後はgit show ハッシュ値で詳細な情報を確認できます。
完璧ですね。

git show db27514

commit db27514bd2c251ed4a64326df69c54cc9f7f521f
Author: username <xxxx@gmail.com>
Date:   Wed Dec 20 19:15:43 2023 +0900

    bugs

diff --git a/index.html b/index.html
index 6fc0def..6b3a39d 100644
--- a/index.html
+++ b/index.html
@@ -8,5 +8,6 @@
 <body>
     <div>追加</div>
     <div>追加2</div>
+    <div>バグ</div>
 </body>
 </html>
\ No newline at end of file
4
3
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
4
3