作成日:2025-02-26, 更新日:2025-08-05
対象となったファイルPATHからコミット一覧取得
$ git log --pretty=format:"%h - %an, %ar : %s" [ファイルパス]
| %h | コミットハッシュ。コミットの短縮形の識別子 |
|---|---|
| %an | コミットを行ったユーザーの名前 |
| %ar | コミットが行われてからの時間(例: "3 days ago") |
| %s | コミットに関連付けられたメッセージ |
サンプル
$ git log --pretty=format:"%h - %an, %ar : %s" app/controller/_parts_type.php 77962fe8 - [ユーザー名], 1 year, 6 months ago : [コミット時のコメント]
サンプル - コミットした日時を知りたい
$ git log --pretty=format:"%h - %an, %ad : %s" --date=short app/controller/_parts_type.php 77962fe8 - [ユーザー名], 2023-09-04 : [コミット時のコメント]
| %h | コミットハッシュ。コミットの短縮形の識別子 |
|---|---|
| %an | コミットを行ったユーザーの名前 |
| %adと--date=short | コミットした日時 |
| %s | コミットに関連付けられたメッセージ |
対象となったファイルPATHの一部からからコミット一覧取得(ワイルドカード的な感じ)
$ git log --pretty=format:"%h - %an, %ar : %s" -- [ワイルドカードを含むファイルパス]
| %h | コミットハッシュ。コミットの短縮形の識別子 |
|---|---|
| %an | コミットを行ったユーザーの名前 |
| %ar | コミットが行われてからの時間(例: "3 days ago") |
| %s | コミットに関連付けられたメッセージ |
| -- | ファイル名のパターン |
サンプル
$ git log --pretty=format:"%h - %an, %ar : %s" -- '*/_parts_type.php' 77962fe8 - [ユーザー名], 1 year, 6 months ago : [コミット時のコメント]
サンプル - コミットした日時を知りたい
$ git log --pretty=format:"%h - %an, %ad : %s" --date=short -- '*/_parts_type.php' 77962fe8 - [ユーザー名], 1 year, 6 months ago : [コミット時のコメント]
修正内容からコミット一覧(詳細付き)を取得
$ git log -S[修正個所] --patch
| --patch | 詳細取得 |
|---|---|
| -S | ピックアップオプション。指定した文字列の追加または削除が含まれるコミットを検索 |
サンプル
$ git log -S'echo $debug;' --patch commit 56fca1c2e417b2bb739a16e339863e68acee110a Author: [ユーザー情報] Date: Tue Oct 3 08:55:06 2023 +0900 ~ 詳細が表示 ~ commit e597b3ab634a5fd39b6936e2377e5965c5aa3e17 Author: [ユーザー情報] Date: Tue Oct 3 08:54:09 2023 +0900 以下、省略
修正内容からコミット一覧(詳細無し)を取得
$ git log --pretty=format:"%h - %an, %ar : %s" -S[修正個所]
| %h | コミットハッシュ。コミットの短縮形の識別子 |
|---|---|
| %an | コミットを行ったユーザーの名前 |
| %ar | コミットが行われてからの時間(例: "3 days ago") |
| %s | コミットに関連付けられたメッセージ |
| --patch | 詳細取得 |
| -S | ピックアップオプション。指定した文字列の追加または削除が含まれるコミットを検索 |
サンプル
$ git log --pretty=format:"%h - %an, %ar : %s" -S'echo $debug;'
コミット詳細を取得
対象ファイルのみ
$ git show --stat [コミットハッシュ]
対象ファイルと修正内容
$ git show [コミットハッシュ]
サンプル
$ git show --stat 77962fe8
commit 77962fe88399e74e34f52451e97e1d950587e3aa
Author: [ユーザー情報]
Date: Mon Sep 4 11:38:50 2023 +0900
未使用のviewファイルをアーカイブ
.../{parts_type.php => _parts_type.php} | 0
以下、略
まとめ
各パラメータ
| %h | コミットハッシュ。コミットの短縮形の識別子 |
|---|---|
| %an | コミットを行ったユーザーの名前 |
| %ar | コミットが行われてからの時間(例: "3 days ago") |
| %adと--date=short | コミットした日時 |
| %s | コミットに関連付けられたメッセージ |
| --patch | 詳細取得 |
| -- | ファイル名のパターン |
| -S | ピックアップオプション。指定した文字列の追加または削除が含まれるコミットを検索 |
よく使いそうな内容
コミットハッシュ、日にち、ユーザー名、コメントの順で表示させたい
| PATHの一部から知りたい |
$ git log --pretty=format:"%h %ad %an : %s" --date=short -- [ファイルPATH] サンプル $ git log --pretty=format:"%h %ad %an : %s" --date=short -- '*/hoge.php' |
|---|---|
| 修正内容の一部から知りたい |
$ git log --pretty=format:"%h %ad %an : %s" --date=short -S[修正個所] サンプル $ git log --pretty=format:"%h %ad %an : %s" --date=short -S'ほげ' |
| PATHの一部から対象を絞り込み、修正内容の一部から知りたい |
$ git log --pretty=format:"%h %ad %an : %s" --date=short -S[修正個所] -- [ファイルPATH] サンプル $ git log --pretty=format:"%h %ad %an : %s" --date=short -S'ほげ' -- '*/hoge.php' |
| コミット詳細を取得 | 対象ファイルのみ
$ git show --stat [コミットハッシュ] 対象ファイル+詳細 $ git show [コミットハッシュ] |
他
修正ファイルのPATHからコミット一覧を取得し、修正内容を調べたい
$ git log --pretty=format:"%h - %an, %ar : %s" -- '*/xxx/xxx.php' d30c7d2c - xxx, 3 years, 6 months ago : 〇〇〇 $ git show d30c7d2c -- */xxx/xxx.php