Git 2 reference · Basics
git diff Command (Git)
Show changes: working tree versus staging area, staged changes (--staged), or between commits and branches.
Git 2
Syntax
git diff [--staged] [COMMIT [COMMIT]] [-- PATH]
Parameters
| Parameter | Description |
|---|---|
(none) |
Unstaged changes. |
--staged |
Changes staged for the next commit. |
A..B / A B |
Between two commits or branches. |
--stat / --name-only |
Summaries. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'Online tea shop' >> README.md
git diff
Output
diff --git a/README.md b/README.md index a00621b..be4fdf8 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # Shop +Online tea shop
Run this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'v2' >> README.md; git add README.md
git diff --staged --stat
git diff --name-only HEAD
Output
README.md | 1 + 1 file changed, 1 insertion(+) README.md
Run this on your computer — see “Get Started” for setup.
Related
git status· Show which files are staged, modified or untracked, and how the branch relates to its upstream.git log· Show commit history: one line per commit, as a graph, filtered by author, date, path or message.git show· Show a commit's message and changes, or the contents of a file at any commit with COMMIT:PATH.- Viewing History and Differences · tutorial