git diff
git
書き方
git diff [--staged] [<commit>] [-- <path>]まだステージに載せていない変更だけを見せます。addした直後は空に見えるので、そのときは--stagedで見ます。
よく使うオプション
| オプション | 意味 |
|---|---|
| --staged | compare the staged snapshot with HEAD (same as --cached) |
| --stat | summary of files and line counts instead of the patch |
| -w | ignore whitespace changes |
| --name-only | list changed paths only |
| <a>...<b> | changes on b since it forked from a |
| -- <path> | restrict to a path; the -- keeps it from being read as a branch |
例
git diffshows only what is NOT staged yet
git diff --stagedshows what git commit would record
git diff main...featurethe work feature added since it left main
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git diff は何をしますか。
まだステージに載せていない変更だけを見せます。addした直後は空に見えるので、そのときは--stagedで見ます。
Q. どう打ちますか。
git diff [--staged] [<commit>] [-- <path>] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-diff