0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

変更されたファイル一覧を取得する

Posted at

特定のコミットで変更されたファイル一覧を取得する

特定のコミットで変更されたファイルの情報だけを取得したい場合は、git showコマンドの--name-onlyオプションを利用します。

git show --name-only <hash>

実行例

C:\myrepository>git show --name-only c19fd19df1c4a92d359e016ea92440224f7cc36d
commit c19fd19df1c4a92d359e016ea92440224f7cc36d
Author: hajime.nakamura <h.nakamura0903@gmail.com>
Date:   Thu Oct 10 20:42:51 2024 +0900

    FIX TYPO

path/to/aaa.txt
path/to/bbb.txt
path/to/ccc.txt

特定のコミットで変更されたファイルとそのステータスを取得する

ファイル名だけでなく、追加、更新、削除などのステータスも確認したい場合は、--name-onlyではなく--name-statusオプションを利用します。

git show --name-status <hash>

実行例

C:\myrepository>git show --name-status c19fd19df1c4a92d359e016ea92440224f7cc36d
commit c19fd19df1c4a92d359e016ea92440224f7cc36d
Author: hajime.nakamura <h.nakamura0903@gmail.com>
Date:   Thu Oct 10 20:42:51 2024 +0900

    FIX TYPO

A    path/to/aaa.txt
D    path/to/bbb.txt
M    path/to/ccc.txt

特定のマージコミットで変更されたファイル一覧を取得する

マージコミットを通常のコミットと同様に扱いたい場合は、-mオプションを使用します。このオプションは、--name-statusオプションと併用できます。

git show -m --name-only <hash>

実行例

C:\myrepository>git show -m --name-only 55e860d0aaba7d970e70e47f5720af621c64bd60
commit 55e860d0aaba7d970e70e47f5720af621c64bd60 (from 269cff0456c1f17a0278caf80e16926e95e7a861) (origin/develop, origin/HEAD, develop)
Merge: 269cff0 1b15adb
Author: hajime.nakamura <h.nakamura0903@gmail.com>
Date:   Tue Oct 22 02:02:19 2024 +0000

    Merge branch 'feature-fix-typo' into 'develop'

    FIX TYPO

    See merge request hajime/nakamura/myrepository!27

path/to/aaa.txt
path/to/bbb.txt
path/to/ccc.txt

2つのコミット間で追加・修正されたファイル一覧を取得する

これまでの説明は単独のコミットに関するものでしたが、2つのコミット間で変更されたファイルを確認したい場合は、git showではなくgit diffコマンドを使用します。git diffコマンドは、-mオプションや--name-statusオプションと組み合わせて利用することもできます。

git diff --name-only <hash1> <hash2>

実行例

C:\myrepository>git diff --name-only 98f72ce386198e7df4adde1ec9afa8414622fcbd 85f9d458bf396fc2e442e60685d993dea607b058

path/to/aaa.txt
path/to/bbb.txt
path/to/ccc.txt

環境情報

C:\myrepository>git --version
git version 2.41.0.windows.1
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?