LoginSignup
264
252

More than 5 years have passed since last update.

よく使う git diff コマンド

Last updated at Posted at 2013-11-30

git diff コマンドは、2つの commit の差分や、 working tree と index の差分などを表示するコマンドである。

実行例

まだ index に add していないモノを表示

git diff

index と working tree の差分を表示するコマンド。

注意: 新規に作成したファイルはこのコマンドでは表示されない。新規に作成されたファイルは Git に track されていないので。

次の commit で反映される変更を表示

git diff --cached

index と HEAD の差分を表示するコマンド。
commit 直前によく実行する。

直前の commit による変更を表示

git diff HEAD^ HEAD

HEAD と HEAD^ の差分を表示するコマンド。
commit 直後によく実行する。

git diff HEAD^ HEAD --stat

--stat オプションを指定すると、差分の統計情報だけを表示する。

オプションについての補足

git diff コマンドは、 default では index と woking tree の差分を表示する。

--cached オプションを指定すると、 index と、ある commit の差分を表示する。
(commit を明示的に指定しない場合は HEAD との差分を表示する。)

設定

コンフィグファイルに以下の設定を書くことで、 git diff を含む Git の大半の出力に色がつく。

[color]
        ui = true

~/.gitconfig に上記設定を書き込むには、以下のコマンドを実行すれば良い。

git config --global color.ui true

リファレンス

264
252
1

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
264
252