0
0

git diff の各コマンドの違い

Posted at

背景

git diff --stat をよく叩くが、git diff には複数の比較方法があるようで、いまいち以下3つの違いが分かっていない。

  • git diff --stat
  • git diff main --stat
  • git diff --cached --stat

調べた結果

  • git diff --stat
    • 前提:追跡されているファイル
    • ステージングと作業環境との差分を出してくれる。
    • 比較対象は ステージング:作業環境
    • git status -s にて ?? になっている新規ファイルは含まれてこない。
  • git add .
    • 変更をステージングに反映
  • git diff --cached --stat
    • 比較対象は ステージング:最後のコミット内容
  • git diff main --stat
    • 比較対象は 現在のブランチ:main
  • git commit -m "コメント"

参考

一度もコミットしていない場合、以下は同じ結果になる

  • git diff --cached --stat
    • 比較対象は ステージング:最後のコミット内容(main)
  • git diff main --stat
    • 比較対象は 現在のブランチ:main

結果

あまりコミットを叩かない現段階では、git diff --stat だけでも良いかもしれない・・・・・

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