git show コマンド
git showコマンドは、Git オブジェクトの詳細情報を表示するために使用します。
git showこのコマンドは、コミット、タグ、ツリーオブジェクト、その他の Git オブジェクトの内容を表示するために使用します。このコマンドは、コミット履歴の確認、コミットの具体的な内容の表示、Git オブジェクトのデバッグに非常に役立ちます。
基本構文
git show [<options>] [<object>]
<object>:表示する Git オブジェクトを指定します。コミットハッシュ、タグ、ブランチ名などを指定できます。<options>:表示するためのオプションまたはフォーマット設定です。
よく使うオプションと使用方法:
| オプション | 説明 | 使用例 |
|---|---|---|
--pretty=format: | 出力フォーマットをカスタマイズします。フォーマット文字列を使用してコミット情報を表示します。 | git show --pretty=format:"%h %s" <commit-hash> |
--name-only | 変更されたファイル名のみを表示します。 | git show --name-only <commit-hash> |
--name-status | 変更されたファイル名と変更ステータス(追加、変更、削除)を表示します。 | git show --name-status <commit-hash> |
--stat | 変更されたファイル、行数、ファイルの変化など、コミットの統計情報を表示します。 | git show --stat <commit-hash> |
--patch | コミットの差分パッチを表示します(デフォルトの動作)。 | git show --patch <commit-hash> |
--color | 読みやすくするためにカラー出力を表示します。 | git show --color <commit-hash> |
--no-patch | パッチを表示せず、コミット情報のみを表示します。 | git show --no-patch <commit-hash> |
--abbrev-commit | 短縮されたコミットハッシュを表示します。 | git show --abbrev-commit <commit-hash> |
--pretty=oneline | コミット情報を1行形式で表示します。 | git show --pretty=oneline <commit-hash> |
一般的な使い方
1. コミットの詳細情報を表示
コミットメッセージ、作者、日付、変更されたファイルなど、コミットの詳細情報を表示します:
git show <commit-hash>
例:
git show 9a0d7b6
2. コミットの差分を表示
コミットに含まれる差分(パッチ)のみを表示します:
git show --patch <commit-hash>
例:
git show --patch 9a0d7b6
3. コミットのファイルリストを表示
コミットで変更されたファイル名のみを表示します:
git show --name-only <commit-hash>
例:
git show --name-only 9a0d7b6
4. コミットの統計情報を表示
変更されたファイルや行数など、コミットの統計情報を表示します:
git show --stat <commit-hash>
例:
git show --stat 9a0d7b6
5. カスタムフォーマットでコミット情報を表示
--pretty=format: を使用してコミット情報の出力フォーマットをカスタマイズします:
git show --pretty=format:"%h - %an, %ar : %s" <commit-hash>
例:
git show --pretty=format:"%h - %an, %ar : %s" 9a0d7b6
6. タグの詳細情報を表示
git show を使用してタグの詳細情報を確認することもできます:
git show <tag>
例:
git show v1.0
その他の拡張
Git 基本操作