Thread View: linux.kernel.git
19 messages
19 total messages
Started by "Julia Evans via GitGitGadget"
Tue, 03 Nov 2026 15:33
[PATCH] doc: git-diff: rewrite EXAMPLES section
Author: "Julia Evans via GitGitGadget"
Date: Tue, 03 Nov 2026 15:33
Date: Tue, 03 Nov 2026 15:33
288 lines
20653 bytes
20653 bytes
From: Julia Evans <julia@jvns.ca>
The top piece of feedback users always give about man pages is always
that they want better examples that are relevant to them.
The EXAMPLES section's structure has remained mostly unchanged since
2007, which was before we knew how people were going to use `git diff`.
Update it with ways of using `git diff` that are popular with Git
users, gathered by asking Mastodon users for their most commonly used
incantations.
Add a note about the EXAMPLES section in the DESCRIPTION since otherwise
readers are unlikely to know it's there. `git diff` is a command where
it's more important than usual to have examples because the command has
so many different forms.
Some design choices:
- Use `--merge-base` instead of `...` since several users said they
find .. vs ... confusing. It's much more obvious what --merge-base
does.
- Use a table format instead of the footnote-style formatting since the
footnote style is quite difficult to follow. It's easier to follow
if the description is right next to the command it's describing.
- Link the options in the examples to make them faster to look up
- Use sub-subsection headings for the different parts to make
them more visually distinct and easy to scan.
Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Julia Evans <julia@jvns.ca>
---
doc: git-diff: rewrite EXAMPLES section
A couple of self-review comments:
* May want to add back the git diff AUTO_MERGE, nobody mentioned it but
it's often nice to include 1 cool little-known example to try to
promote it.
* I'm not 100% sure about the table format, it does make it more
compact which is really nice and makes it much more readable, but on
an 80-character terminal there is some wrapping. One potential con is
that it means we can't include as many details about what the command
does. From my point of view that's a good thing because in a "cheat
sheet" format it's very important to be concise, and people can
always read the rest of the man page for the details.
Here's what one of the tables looks like on an 80-character terminal
with a little bit of wrapping.
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ
βIgnore all whitespace β git diff β
βchanges β --ignore-all-space β
βββββββββββββββββββββββββββΌββββββββββββββββββββββββ€
βShow which individual β git diff --word-diff β
βwords changed instead of β β
βthe whole line β β
βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββ
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2293%2Fjvns%2Fdiff-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2293/jvns/diff-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2293
Documentation/diff-options.adoc | 5 ++
Documentation/git-diff.adoc | 149 ++++++++++++++++++--------------
2 files changed, 87 insertions(+), 67 deletions(-)
diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc
index e605d28678..2dc54fa00e 100644
--- a/Documentation/diff-options.adoc
+++ b/Documentation/diff-options.adoc
@@ -201,6 +201,7 @@ diff" algorithm internally.
include::diff-algorithm-option.adoc[]
+[[stat]]
`--stat[=<width>[,<name-width>[,<count>]]]`::
Generate a diffstat. By default, as much space as necessary
will be used for the filename part, and the rest for the graph
@@ -318,12 +319,14 @@ Without this option, pathnames with "unusual" characters are quoted as
explained for the configuration variable `core.quotePath` (see
linkgit:git-config[1]).
+[[name_only]]
`--name-only`::
Show only the name of each changed file in the post-image tree.
The file names are often encoded in UTF-8.
For more information see the discussion about encoding in the linkgit:git-log[1]
manual page.
+[[name_status]]
`--name-status`::
Show only the name(s) and status of each changed file. See the description
of the `--diff-filter` option on what the status letters mean.
@@ -417,6 +420,7 @@ endif::git-diff[]
Ignore changes in amount of whitespace. This ignores whitespace
at line end, and considers all other sequences of one or
more whitespace characters to be equivalent.
+[[ignore_all_space]]
`ignore-all-space`::
Ignore whitespace when comparing lines. This ignores differences
even if one line has whitespace where the other line has none.
@@ -432,6 +436,7 @@ endif::git-diff[]
used to override configuration settings. It is the same as
`--color-moved-ws=no`.
+[[word_diff]]
`--word-diff[=<mode>]`::
By default, words are delimited by whitespace; see
`--word-diff-regex` below. The _<mode>_ defaults to `plain`, and
diff --git a/Documentation/git-diff.adoc b/Documentation/git-diff.adoc
index 272331afba..8d9de30f64 100644
--- a/Documentation/git-diff.adoc
+++ b/Documentation/git-diff.adoc
@@ -23,6 +23,9 @@ between the index and a tree, changes between two trees, changes resulting
from a merge, changes between two blob objects, or changes between two
files on disk.
+The <<EXAMPLES,EXAMPLES>> section has examples of the most common ways
+to diff.
+
`git diff [<options>] [--] [<path>...]`::
This form is to view the changes you made relative to
@@ -160,78 +163,90 @@ section "3-Way Merge" for detailed information.
include::diff-format.adoc[]
+[[EXAMPLES]]
EXAMPLES
--------
-Various ways to check your working tree::
-+
-------------
-$ git diff <1>
-$ git diff --cached <2>
-$ git diff HEAD <3>
-$ git diff AUTO_MERGE <4>
-------------
-+
-<1> Changes in the working tree not yet staged for the next commit.
-<2> Changes between the index and your last commit; what you
- would be committing if you run `git commit` without `-a` option.
-<3> Changes in the working tree since your last commit; what you
- would be committing if you run `git commit -a`
-<4> Changes in the working tree you've made to resolve textual
- conflicts so far.
-
-Comparing with arbitrary commits::
-+
-------------
-$ git diff test <1>
-$ git diff HEAD -- ./test <2>
-$ git diff HEAD^ HEAD <3>
-------------
-+
-<1> Instead of using the tip of the current branch, compare with the
- tip of "test" branch.
-<2> Instead of comparing with the tip of "test" branch, compare with
- the tip of the current branch, but limit the comparison to the
- file "test".
-<3> Compare the version before the last commit and the last commit.
-
-Comparing branches::
-+
-------------
-$ git diff topic master <1>
-$ git diff topic..master <2>
-$ git diff topic...master <3>
-------------
-+
-<1> Changes between the tips of the topic and the master branches.
-<2> Same as above.
-<3> Changes that occurred on the master branch since when the topic
- branch was started off it.
+Diff uncommitted changes
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+`git diff` will show the files from the "before" column as deleted and
+from the "after" column as added.
+
+[cols="1,1"]
+|===
+|Show unstaged changes
+|`git diff`
+
+|Show staged changes
+|`git diff --staged`
+
+|Show all changes since the latest commit
+|`git diff HEAD`
+|===
+
+Diff a specific file/directory
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can usually put a filename or directory at the end to restrict the
+diff to that file/directory. You don't always need to put a `--`, but it
+makes it unambiguous.
+
+[cols="1,1"]
+|===
+|Show how `file.txt` has changed since `main`
+|`git diff main -- file.txt`
+
+|Show unstaged changes for `file.txt`
+|`git diff -- file.txt`
+
+|Show unstaged changes in `dir/`
+|`git diff -- ./dir`
+|===
+
+Diff branches or commits
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+[cols="1,1"]
+|===
+|Show changes on the `topic` branch since it branched off `main`
+|`git diff --merge-base main topic`
+
+|Show changes between the `topic` branch and the `main` branch
+|`git diff main topic`
+
+|Show changes between commit `ff11cc` and `HEAD`
+|`git diff ff11cc HEAD`
+|===
+
+Options to summarize the output
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[cols="1,1"]
+|===
+|Show how many lines in each file were changed
+|`git diff` <<stat,`--stat`>>
+
+|Only show names of changed files
+|`git diff` <<name_only,`--name-only`>>
+
+|Only show filenames and whether they were modified/deleted/added
+|`git diff` <<name_status,`--name-status`>>
+|===
+
+Options to display the diff in another way
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[cols="1,1"]
+|===
+|Ignore all whitespace changes
+|`git diff` <<ignore_all_space,`--ignore-all-space`>>
+
+|Show which individual words changed instead of the whole line
+|`git diff` <<word_diff,`--word-diff`>>
+|===
-Limiting the diff output::
-+
-------------
-$ git diff --diff-filter=MRC <1>
-$ git diff --name-status <2>
-$ git diff arch/i386 include/asm-i386 <3>
-------------
-+
-<1> Show only modification, rename, and copy, but not addition
- or deletion.
-<2> Show only names and the nature of change, but not actual
- diff output.
-<3> Limit diff output to named subtrees.
-Munging the diff output::
-+
-------------
-$ git diff --find-copies-harder -B -C <1>
-$ git diff -R <2>
-------------
-+
-<1> Spend extra cycles to find renames, copies and complete
- rewrites (very expensive).
-<2> Output diff in reverse.
CONFIGURATION
-------------
base-commit: 7e34d8174dcda3435d1404c9a30bef46afe6c13e
--
gitgitgadget
Re: [PATCH] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Tue, 03 Nov 2026 19:44
Date: Tue, 03 Nov 2026 19:44
64 lines
15473 bytes
15473 bytes
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes: > Here's what one of the tables looks like on an 80-character terminal > with a little bit of wrapping. > > βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ > βIgnore all whitespace β git diff β > βchanges β --ignore-all-space β > βββββββββββββββββββββββββββΌββββββββββββββββββββββββ€ > βShow which individual β git diff --word-diff β > βwords changed instead of β β > βthe whole line β β > βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββ Personally, I would not want to see these line-wrapped sentences in tables, which makes it impossible to cut-and-paste. But preferences vary from person to person, of course, on these things. > -Various ways to check your working tree:: > -+ > ------------- > -$ git diff <1> > -$ git diff --cached <2> > -$ git diff HEAD <3> > -$ git diff AUTO_MERGE <4> > ------------- > -+ > -<1> Changes in the working tree not yet staged for the next commit. > -<2> Changes between the index and your last commit; what you > - would be committing if you run `git commit` without `-a` option. > -<3> Changes in the working tree since your last commit; what you > - would be committing if you run `git commit -a` > -<4> Changes in the working tree you've made to resolve textual > - conflicts so far. > ... > +[cols="1,1"] > +|=== > +|Show unstaged changes > +|`git diff` > + > +|Show staged changes > +|`git diff --staged` Do not sneak this change into an unrelated "change the format to use table to make it readable" topic. Doing this change to just this single example would be a severe regression. Look at SYNOPSIS of "git help diff" and notice there is no mention of "--staged". The description on "--cached" explains it as a synonym for it. If we wanted to promote "--staged" (which I would not personally support), we'd need to do matching changes to the main part of the text. > +|Show all changes since the latest commit > +|`git diff HEAD` > +|=== Yes, as you mentioned in the commentary, loss of AUTO_MERGE is a regression. I do not see a reason why you needed to drop it? Is it because some external limitation like you cannot have a table with more than 3 rows or something? Thanks.
Re: [PATCH] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Tue, 03 Nov 2026 20:33
Date: Tue, 03 Nov 2026 20:33
42 lines
14423 bytes
14423 bytes
"Julia Evans" <julia@jvns.ca> writes: >>> +|Show staged changes >>> +|`git diff --staged` >> >> Do not sneak this change into an unrelated "change the format to use >> table to make it readable" topic. Doing this change to just this >> single example would be a severe regression. > > I can change it back, I didn't realize it would be an issue. Changing this example alone without checking its fit in the wider context is what made it problematic. I do not personally support "cached to staged" because I consider it mostly a meaningless churn, but that is different from saying I will veto it. I just wanted to see a bit more consistency; without changing the main text, the change to the example made it look like a very odd thing to have there. You see the option named "--staged" but it is explained nowhere other than being a synonym to another option that is much more widely explained. > I dropped it because I wanted to start with just the commands that > people said they found useful, and it can be hard to introduce > too many "new" commands that aren't well-known already. > > That said I think `git diff AUTO_MERGE` seems useful and I'm happy > to put it back. FWIW, what is in the current document was added by choosing what were found useful. So you would want to think twice (note: this is very different from "do not change") before removing existing ones or replacing them with something else. After spending a significant amount of effort on these documentation updates you are making, if a new person came and rewrote them again without understanding or paying much attention to your reasoning behind how you arrived at your version, I would imagine that you would feel terrible. Please give the last person who wrote these documents the same courtesy and respect. Thanks.
Re: [PATCH] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Tue, 03 Nov 2026 21:42
Date: Tue, 03 Nov 2026 21:42
12 lines
13108 bytes
13108 bytes
"Julia Evans" <julia@jvns.ca> writes: > It's very hard to understand from the Git history the reasons for > adding examples that were added 20 years ago, for example > in 803f498c03b where these were added, especially since the commit > messages from 20 years ago tend to be a lot more terse. Sure. But that is why you send patches here to invite people to comment on. > I do hear that AUTO_MERGE was added more recently.
[PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: "Julia Evans via GitGitGadget"
Date: Thu, 05 Nov 2026 15:40
Date: Thu, 05 Nov 2026 15:40
545 lines
32092 bytes
32092 bytes
From: Julia Evans <julia@jvns.ca>
The top piece of feedback users always give about man pages is always
that they want better examples that are relevant to them.
The EXAMPLES section's structure has remained mostly unchanged since
2007, which was before we knew how people were going to use `git diff`.
Update it with ways of using `git diff` that are popular with Git
users, gathered by asking Mastodon users for their most commonly used
incantations. Keep the example that was added since 2007
(`git diff AUTO_MERGE`), rewording it to use the more familiar term
"merge conflict" instead of "textual conflict".
Add a note about the EXAMPLES section in the DESCRIPTION since otherwise
readers are unlikely to know it's there. `git diff` is a command where
it's more important than usual to have examples because the command has
so many different forms.
Some design choices:
- Mention both `git diff --staged` and `git diff --cached`, because
"staged" is the term the Git user interface uses and several users
said they find it easier to understand. Add an entry for --staged
saying that it's a synonym. Like with `git switch`, and `git checkout`
it's useful to leave the older version for folks who are used to using
`git diff --cached` since we've seen that many people who are used to
using a command don't see any value in changing how they use it.
- Use a definition list for the examples instead of the footnote style,
so that the description and the example are right next to each other
and it's easier to read.
- Use `--merge-base` instead of `...` since several users said they
find .. vs ... confusing. It's much more obvious what --merge-base
does.
- Link the options in the examples to make them faster to look up
- Use sub-subsection headings for the different parts to make
them more visually distinct and easy to scan.
Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Julia Evans <julia@jvns.ca>
---
doc: git-diff: rewrite EXAMPLES section
changes in v2:
* Switch from tables to a definition list, to avoid wrapping but still
staying relatively compact.
* Mention git diff --cached alongside git diff --staged so folks can
use whichever version they prefer, and update the commit message with
some notes about that. It's an example of one of many situations in
Git where what's best to recommend for new users and what's best for
long-term users is not necessarily the same.
* Put back AUTO_MERGE (thanks to Junio for pointing out that it was
added much more recently than all the rest of the examples)
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2293%2Fjvns%2Fdiff-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2293/jvns/diff-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2293
Range-diff vs v1:
1: 46728e7b7a ! 1: ec565ce334 doc: git-diff: rewrite EXAMPLES section
@@ Commit message
2007, which was before we knew how people were going to use `git diff`.
Update it with ways of using `git diff` that are popular with Git
users, gathered by asking Mastodon users for their most commonly used
- incantations.
+ incantations. Keep the example that was added since 2007
+ (`git diff AUTO_MERGE`), rewording it to use the more familiar term
+ "merge conflict" instead of "textual conflict".
Add a note about the EXAMPLES section in the DESCRIPTION since otherwise
readers are unlikely to know it's there. `git diff` is a command where
@@ Commit message
Some design choices:
+ - Mention both `git diff --staged` and `git diff --cached`, because
+ "staged" is the term the Git user interface uses and several users
+ said they find it easier to understand. Add an entry for --staged
+ saying that it's a synonym. Like with `git switch`, and `git checkout`
+ it's useful to leave the older version for folks who are used to using
+ `git diff --cached` since we've seen that many people who are used to
+ using a command don't see any value in changing how they use it.
+ - Use a definition list for the examples instead of the footnote style,
+ so that the description and the example are right next to each other
+ and it's easier to read.
- Use `--merge-base` instead of `...` since several users said they
find .. vs ... confusing. It's much more obvious what --merge-base
does.
- - Use a table format instead of the footnote-style formatting since the
- footnote style is quite difficult to follow. It's easier to follow
- if the description is right next to the command it's describing.
- Link the options in the examples to make them faster to look up
- Use sub-subsection headings for the different parts to make
them more visually distinct and easy to scan.
@@ Documentation/diff-options.adoc: endif::git-diff[]
`--word-diff-regex` below. The _<mode>_ defaults to `plain`, and
## Documentation/git-diff.adoc ##
+@@ Documentation/git-diff.adoc: SYNOPSIS
+ --------
+ [synopsis]
+ git diff [<options>] [<commit>] [--] [<path>...]
+-git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]
++git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...]
+ git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]
+ git diff [<options>] <commit>...<commit> [--] [<path>...]
+ git diff [<options>] <blob> <blob>
@@ Documentation/git-diff.adoc: between the index and a tree, changes between two trees, changes resulting
from a merge, changes between two blob objects, or changes between two
files on disk.
@@ Documentation/git-diff.adoc: between the index and a tree, changes between two t
`git diff [<options>] [--] [<path>...]`::
This form is to view the changes you made relative to
+@@ Documentation/git-diff.adoc: files on disk.
+ difference. All such pathspecs must be relative as they
+ apply to both sides of the diff.
+
+-`git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]`::
++`git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...]`::
+
+ This form is to view the changes you staged for the next
+ commit relative to the named _<commit>_. Typically you
+@@ Documentation/git-diff.adoc: files on disk.
+ do not give _<commit>_, it defaults to `HEAD`.
+ If `HEAD` does not exist (e.g. unborn branches) and
+ _<commit>_ is not given, it shows all staged changes.
+- `--staged` is a synonym of `--cached`.
++ `--cached` is a synonym of `--staged`.
+ +
+ If `--merge-base` is given, instead of using _<commit>_, use the merge base
+ of _<commit>_ and `HEAD`. `git diff --cached --merge-base A` is equivalent to
+-`git diff --cached $(git merge-base A HEAD)`.
++`git diff --staged $(git merge-base A HEAD)`.
+
+ `git diff [<options>] [--merge-base] <commit> [--] [<path>...]`::
+
@@ Documentation/git-diff.adoc: section "3-Way Merge" for detailed information.
include::diff-format.adoc[]
@@ Documentation/git-diff.adoc: section "3-Way Merge" for detailed information.
- branch was started off it.
+Diff uncommitted changes
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+-Limiting the diff output::
+-+
+-------------
+-$ git diff --diff-filter=MRC <1>
+-$ git diff --name-status <2>
+-$ git diff arch/i386 include/asm-i386 <3>
+-------------
+-+
+-<1> Show only modification, rename, and copy, but not addition
+- or deletion.
+-<2> Show only names and the nature of change, but not actual
+- diff output.
+-<3> Limit diff output to named subtrees.
++Show unstaged changes::
++`git diff`
+
+-Munging the diff output::
+-+
+-------------
+-$ git diff --find-copies-harder -B -C <1>
+-$ git diff -R <2>
+-------------
+-+
+-<1> Spend extra cycles to find renames, copies and complete
+- rewrites (very expensive).
+-<2> Output diff in reverse.
++Show staged changes::
++`git diff --staged` or `git diff --cached`
+
-+`git diff` will show the files from the "before" column as deleted and
-+from the "after" column as added.
-+
-+[cols="1,1"]
-+|===
-+|Show unstaged changes
-+|`git diff`
-+
-+|Show staged changes
-+|`git diff --staged`
++Show all changes since the latest commit::
++`git diff HEAD`
+
-+|Show all changes since the latest commit
-+|`git diff HEAD`
-+|===
++Show changes made to resolve a merge conflict::
++`git diff AUTO_MERGE`
+
+Diff a specific file/directory
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ Documentation/git-diff.adoc: section "3-Way Merge" for detailed information.
+diff to that file/directory. You don't always need to put a `--`, but it
+makes it unambiguous.
+
-+[cols="1,1"]
-+|===
-+|Show how `file.txt` has changed since `main`
-+|`git diff main -- file.txt`
++Show how `file.txt` has changed since `main`::
++`git diff main -- file.txt`
+
-+|Show unstaged changes for `file.txt`
-+|`git diff -- file.txt`
++Show unstaged changes for `file.txt`::
++`git diff -- file.txt`
+
-+|Show unstaged changes in `dir/`
-+|`git diff -- ./dir`
-+|===
++Show unstaged changes in `dir/`::
++`git diff -- ./dir`
+
+Diff branches or commits
+~~~~~~~~~~~~~~~~~~~~~~~~
+
-+[cols="1,1"]
-+|===
-+|Show changes on the `topic` branch since it branched off `main`
-+|`git diff --merge-base main topic`
++Show changes on the `topic` branch since it branched off `main`::
++`git diff --merge-base main topic`
+
-+|Show changes between the `topic` branch and the `main` branch
-+|`git diff main topic`
++Show changes between the `topic` branch and the `main` branch::
++`git diff main topic`
+
-+|Show changes between commit `ff11cc` and `HEAD`
-+|`git diff ff11cc HEAD`
-+|===
++Show changes between commit `ff11cc` and `HEAD`::
++`git diff ff11cc HEAD`
+
+Options to summarize the output
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
-+[cols="1,1"]
-+|===
-+|Show how many lines in each file were changed
-+|`git diff` <<stat,`--stat`>>
++Show how many lines in each file were changed::
++`git diff` <<stat,`--stat`>>
+
-+|Only show names of changed files
-+|`git diff` <<name_only,`--name-only`>>
++Only show names of changed files::
++`git diff` <<name_only,`--name-only`>>
+
-+|Only show filenames and whether they were modified/deleted/added
-+|`git diff` <<name_status,`--name-status`>>
-+|===
++Only show filenames and whether they were modified/deleted/added::
++`git diff` <<name_status,`--name-status`>>
+
+Options to display the diff in another way
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
-+[cols="1,1"]
-+|===
-+|Ignore all whitespace changes
-+|`git diff` <<ignore_all_space,`--ignore-all-space`>>
++Ignore all whitespace changes::
++`git diff` <<ignore_all_space,`--ignore-all-space`>>
+
-+|Show which individual words changed instead of the whole line
-+|`git diff` <<word_diff,`--word-diff`>>
-+|===
-
--Limiting the diff output::
--+
--------------
--$ git diff --diff-filter=MRC <1>
--$ git diff --name-status <2>
--$ git diff arch/i386 include/asm-i386 <3>
--------------
--+
--<1> Show only modification, rename, and copy, but not addition
-- or deletion.
--<2> Show only names and the nature of change, but not actual
-- diff output.
--<3> Limit diff output to named subtrees.
-
--Munging the diff output::
--+
--------------
--$ git diff --find-copies-harder -B -C <1>
--$ git diff -R <2>
--------------
--+
--<1> Spend extra cycles to find renames, copies and complete
-- rewrites (very expensive).
--<2> Output diff in reverse.
++Show which individual words changed instead of the whole line::
++`git diff` <<word_diff,`--word-diff`>>
CONFIGURATION
-------------
Documentation/diff-options.adoc | 5 ++
Documentation/git-diff.adoc | 140 ++++++++++++++++----------------
2 files changed, 74 insertions(+), 71 deletions(-)
diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc
index e605d28678..2dc54fa00e 100644
--- a/Documentation/diff-options.adoc
+++ b/Documentation/diff-options.adoc
@@ -201,6 +201,7 @@ diff" algorithm internally.
include::diff-algorithm-option.adoc[]
+[[stat]]
`--stat[=<width>[,<name-width>[,<count>]]]`::
Generate a diffstat. By default, as much space as necessary
will be used for the filename part, and the rest for the graph
@@ -318,12 +319,14 @@ Without this option, pathnames with "unusual" characters are quoted as
explained for the configuration variable `core.quotePath` (see
linkgit:git-config[1]).
+[[name_only]]
`--name-only`::
Show only the name of each changed file in the post-image tree.
The file names are often encoded in UTF-8.
For more information see the discussion about encoding in the linkgit:git-log[1]
manual page.
+[[name_status]]
`--name-status`::
Show only the name(s) and status of each changed file. See the description
of the `--diff-filter` option on what the status letters mean.
@@ -417,6 +420,7 @@ endif::git-diff[]
Ignore changes in amount of whitespace. This ignores whitespace
at line end, and considers all other sequences of one or
more whitespace characters to be equivalent.
+[[ignore_all_space]]
`ignore-all-space`::
Ignore whitespace when comparing lines. This ignores differences
even if one line has whitespace where the other line has none.
@@ -432,6 +436,7 @@ endif::git-diff[]
used to override configuration settings. It is the same as
`--color-moved-ws=no`.
+[[word_diff]]
`--word-diff[=<mode>]`::
By default, words are delimited by whitespace; see
`--word-diff-regex` below. The _<mode>_ defaults to `plain`, and
diff --git a/Documentation/git-diff.adoc b/Documentation/git-diff.adoc
index 272331afba..f15e56633e 100644
--- a/Documentation/git-diff.adoc
+++ b/Documentation/git-diff.adoc
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[synopsis]
git diff [<options>] [<commit>] [--] [<path>...]
-git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]
+git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...]
git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]
git diff [<options>] <commit>...<commit> [--] [<path>...]
git diff [<options>] <blob> <blob>
@@ -23,6 +23,9 @@ between the index and a tree, changes between two trees, changes resulting
from a merge, changes between two blob objects, or changes between two
files on disk.
+The <<EXAMPLES,EXAMPLES>> section has examples of the most common ways
+to diff.
+
`git diff [<options>] [--] [<path>...]`::
This form is to view the changes you made relative to
@@ -44,7 +47,7 @@ files on disk.
difference. All such pathspecs must be relative as they
apply to both sides of the diff.
-`git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]`::
+`git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...]`::
This form is to view the changes you staged for the next
commit relative to the named _<commit>_. Typically you
@@ -52,11 +55,11 @@ files on disk.
do not give _<commit>_, it defaults to `HEAD`.
If `HEAD` does not exist (e.g. unborn branches) and
_<commit>_ is not given, it shows all staged changes.
- `--staged` is a synonym of `--cached`.
+ `--cached` is a synonym of `--staged`.
+
If `--merge-base` is given, instead of using _<commit>_, use the merge base
of _<commit>_ and `HEAD`. `git diff --cached --merge-base A` is equivalent to
-`git diff --cached $(git merge-base A HEAD)`.
+`git diff --staged $(git merge-base A HEAD)`.
`git diff [<options>] [--merge-base] <commit> [--] [<path>...]`::
@@ -160,78 +163,73 @@ section "3-Way Merge" for detailed information.
include::diff-format.adoc[]
+[[EXAMPLES]]
EXAMPLES
--------
-Various ways to check your working tree::
-+
-------------
-$ git diff <1>
-$ git diff --cached <2>
-$ git diff HEAD <3>
-$ git diff AUTO_MERGE <4>
-------------
-+
-<1> Changes in the working tree not yet staged for the next commit.
-<2> Changes between the index and your last commit; what you
- would be committing if you run `git commit` without `-a` option.
-<3> Changes in the working tree since your last commit; what you
- would be committing if you run `git commit -a`
-<4> Changes in the working tree you've made to resolve textual
- conflicts so far.
-
-Comparing with arbitrary commits::
-+
-------------
-$ git diff test <1>
-$ git diff HEAD -- ./test <2>
-$ git diff HEAD^ HEAD <3>
-------------
-+
-<1> Instead of using the tip of the current branch, compare with the
- tip of "test" branch.
-<2> Instead of comparing with the tip of "test" branch, compare with
- the tip of the current branch, but limit the comparison to the
- file "test".
-<3> Compare the version before the last commit and the last commit.
-
-Comparing branches::
-+
-------------
-$ git diff topic master <1>
-$ git diff topic..master <2>
-$ git diff topic...master <3>
-------------
-+
-<1> Changes between the tips of the topic and the master branches.
-<2> Same as above.
-<3> Changes that occurred on the master branch since when the topic
- branch was started off it.
+Diff uncommitted changes
+~~~~~~~~~~~~~~~~~~~~~~~~
-Limiting the diff output::
-+
-------------
-$ git diff --diff-filter=MRC <1>
-$ git diff --name-status <2>
-$ git diff arch/i386 include/asm-i386 <3>
-------------
-+
-<1> Show only modification, rename, and copy, but not addition
- or deletion.
-<2> Show only names and the nature of change, but not actual
- diff output.
-<3> Limit diff output to named subtrees.
+Show unstaged changes::
+`git diff`
-Munging the diff output::
-+
-------------
-$ git diff --find-copies-harder -B -C <1>
-$ git diff -R <2>
-------------
-+
-<1> Spend extra cycles to find renames, copies and complete
- rewrites (very expensive).
-<2> Output diff in reverse.
+Show staged changes::
+`git diff --staged` or `git diff --cached`
+
+Show all changes since the latest commit::
+`git diff HEAD`
+
+Show changes made to resolve a merge conflict::
+`git diff AUTO_MERGE`
+
+Diff a specific file/directory
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can usually put a filename or directory at the end to restrict the
+diff to that file/directory. You don't always need to put a `--`, but it
+makes it unambiguous.
+
+Show how `file.txt` has changed since `main`::
+`git diff main -- file.txt`
+
+Show unstaged changes for `file.txt`::
+`git diff -- file.txt`
+
+Show unstaged changes in `dir/`::
+`git diff -- ./dir`
+
+Diff branches or commits
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Show changes on the `topic` branch since it branched off `main`::
+`git diff --merge-base main topic`
+
+Show changes between the `topic` branch and the `main` branch::
+`git diff main topic`
+
+Show changes between commit `ff11cc` and `HEAD`::
+`git diff ff11cc HEAD`
+
+Options to summarize the output
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Show how many lines in each file were changed::
+`git diff` <<stat,`--stat`>>
+
+Only show names of changed files::
+`git diff` <<name_only,`--name-only`>>
+
+Only show filenames and whether they were modified/deleted/added::
+`git diff` <<name_status,`--name-status`>>
+
+Options to display the diff in another way
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Ignore all whitespace changes::
+`git diff` <<ignore_all_space,`--ignore-all-space`>>
+
+Show which individual words changed instead of the whole line::
+`git diff` <<word_diff,`--word-diff`>>
CONFIGURATION
-------------
base-commit: 0ffa3e35c7c82ab8d0de226149fb03b3f7674d05
--
gitgitgadget
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Thu, 05 Nov 2026 16:46
Date: Thu, 05 Nov 2026 16:46
35 lines
14102 bytes
14102 bytes
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes: > +-git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...] > ++git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...] This goes against what you said earlier, which was > - Mention both `git diff --staged` and `git diff --cached`, because > "staged" is the term the Git user interface uses and several users > said they find it easier to understand. Add an entry for --staged > saying that it's a synonym. Like with `git switch`, and `git checkout` > it's useful to leave the older version for folks who are used to using > `git diff --cached` since we've seen that many people who are used to > using a command don't see any value in changing how they use it. Perhaps (--cached|--staged) or have two lines (i.e., turn the range diff into > + git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...] > ++git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...] or something). > +@@ Documentation/git-diff.adoc: files on disk. > + do not give _<commit>_, it defaults to `HEAD`. > + If `HEAD` does not exist (e.g. unborn branches) and > + _<commit>_ is not given, it shows all staged changes. > +- `--staged` is a synonym of `--cached`. > ++ `--cached` is a synonym of `--staged`. And this is the other way around. Other than that, the rest, including the resurrection of AUTO_MERGE, looked OK.
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Tuomas Ahola
Date: Thu, 05 Nov 2026 17:23
Date: Thu, 05 Nov 2026 17:23
14 lines
10036 bytes
10036 bytes
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> wrote: > -------- > [synopsis] > git diff [<options>] [<commit>] [--] [<path>...] > -git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...] > +git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...] > git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...] > git diff [<options>] <commit>...<commit> [--] [<path>...] > git diff [<options>] <blob> <blob> Sorry, that breaks the test number 0450.218. Please change the synopsis of "git diff -h" as well.
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Thu, 05 Nov 2026 18:18
Date: Thu, 05 Nov 2026 18:18
47 lines
14577 bytes
14577 bytes
Junio C Hamano <gitster@pobox.com> writes: > "Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes: > >> +-git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...] >> ++git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...] > > This goes against what you said earlier, which was > >> - Mention both `git diff --staged` and `git diff --cached`, because >> "staged" is the term the Git user interface uses and several users >> said they find it easier to understand. Add an entry for --staged >> saying that it's a synonym. Like with `git switch`, and `git checkout` >> it's useful to leave the older version for folks who are used to using >> `git diff --cached` since we've seen that many people who are used to >> using a command don't see any value in changing how they use it. > > Perhaps (--cached|--staged) or have two lines (i.e., turn the range > diff into > >> + git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...] >> ++git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...] > > or something). Clarification. The point is that there is a difference between giving wider exposure to "--staged" as an accepted synonym and swapping offical option with the synonym, let alone deprecating "--cached". You may have heard from several users that they like the word "staged", but I am sure there are more than several thousand users who have been using Git since before the synonym was introduced. >> +@@ Documentation/git-diff.adoc: files on disk. >> + do not give _<commit>_, it defaults to `HEAD`. >> + If `HEAD` does not exist (e.g. unborn branches) and >> + _<commit>_ is not given, it shows all staged changes. >> +- `--staged` is a synonym of `--cached`. >> ++ `--cached` is a synonym of `--staged`. > > And this is the other way around. > > Other than that, the rest, including the resurrection of AUTO_MERGE, > looked OK.
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Thu, 05 Nov 2026 19:45
Date: Thu, 05 Nov 2026 19:45
18 lines
13308 bytes
13308 bytes
Tuomas Ahola <taahol@utu.fi> writes: > "Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> wrote: > >> -------- >> [synopsis] >> git diff [<options>] [<commit>] [--] [<path>...] >> -git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...] >> +git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...] >> git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...] >> git diff [<options>] <commit>...<commit> [--] [<path>...] >> git diff [<options>] <blob> <blob> > > Sorry, that breaks the test number 0450.218. Please change the synopsis of > "git diff -h" as well. Ah, good point. Thanks for noticing.
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Thu, 05 Nov 2026 19:46
Date: Thu, 05 Nov 2026 19:46
66 lines
15418 bytes
15418 bytes
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Julia Evans <julia@jvns.ca> > > The top piece of feedback users always give about man pages is always > that they want better examples that are relevant to them. I'll add this squashable fix-up on top before queuing; the change to the code is because otherwise this change would break a test. Thanks. Documentation/git-diff.adoc | 8 ++++---- builtin/diff.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git c/Documentation/git-diff.adoc w/Documentation/git-diff.adoc index f15e56633e..42360f9b5e 100644 --- c/Documentation/git-diff.adoc +++ w/Documentation/git-diff.adoc @@ -10,7 +10,7 @@ SYNOPSIS -------- [synopsis] git diff [<options>] [<commit>] [--] [<path>...] -git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...] +git diff [<options>] (--cached|--staged) [--merge-base] [<commit>] [--] [<path>...] git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...] git diff [<options>] <commit>...<commit> [--] [<path>...] git diff [<options>] <blob> <blob> @@ -47,7 +47,7 @@ to diff. difference. All such pathspecs must be relative as they apply to both sides of the diff. -`git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...]`:: +`git diff [<options>] (--cached|--staged) [--merge-base] [<commit>] [--] [<path>...]`:: This form is to view the changes you staged for the next commit relative to the named _<commit>_. Typically you @@ -55,10 +55,10 @@ to diff. do not give _<commit>_, it defaults to `HEAD`. If `HEAD` does not exist (e.g. unborn branches) and _<commit>_ is not given, it shows all staged changes. - `--cached` is a synonym of `--staged`. + `--staged` is a synonym of `--cached`. + If `--merge-base` is given, instead of using _<commit>_, use the merge base -of _<commit>_ and `HEAD`. `git diff --cached --merge-base A` is equivalent to +of _<commit>_ and `HEAD`. `git diff --staged --merge-base A` is equivalent to `git diff --staged $(git merge-base A HEAD)`. `git diff [<options>] [--merge-base] <commit> [--] [<path>...]`:: diff --git c/builtin/diff.c w/builtin/diff.c index 18b1083e98..13fe8a21e0 100644 --- c/builtin/diff.c +++ w/builtin/diff.c @@ -31,7 +31,7 @@ static const char builtin_diff_usage[] = "git diff [<options>] [<commit>] [--] [<path>...]\n" -" or: git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]\n" +" or: git diff [<options>] (--cached|--staged) [--merge-base] [<commit>] [--] [<path>...]\n" " or: git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]\n" " or: git diff [<options>] <commit>...<commit> [--] [<path>...]\n" " or: git diff [<options>] <blob> <blob>\n"
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Sun, 08 Nov 2026 04:35
Date: Sun, 08 Nov 2026 04:35
26 lines
13743 bytes
13743 bytes
Jeff King <peff@peff.net> writes: > On Thu, Nov 05, 2026 at 03:40:17PM +0000, Julia Evans via GitGitGadget wrote: > >> +[[name_only]] >> `--name-only`:: >> Show only the name of each changed file in the post-image tree. >> The file names are often encoded in UTF-8. >> For more information see the discussion about encoding in the linkgit:git-log[1] >> manual page. > > Sadly this syntax seems to work with Asciidoctor, but not Asciidoc. The > latter doesn't create the anchors, and then xmlto complaints that the > result doesn't validate. An offtopic tangent but didn't we repeatedly float ideas to drop support for AsciiDoc, make sure our documentation set renders well only with AsciiDoctor, and tell folks who do not use AsciiDoctor to use pre-rendered documentation pages from git-htmldocs.git and git-manpages.git repositories at https://git.kernel.org/pub/scm/git/ during the past several months? Perhaps I should add an entry to the BreakingChanges document (well, I know I know I do not think it belongs there, but since we hit this so many times already .....).
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: "D. Ben Knoble"
Date: Mon, 09 Nov 2026 12:48
Date: Mon, 09 Nov 2026 12:48
19 lines
10879 bytes
10879 bytes
On Thu, Nov 5, 2026 at 1:18β―PM Junio C Hamano <gitster@pobox.com> wrote: > Clarification. > > The point is that there is a difference between giving wider > exposure to "--staged" as an accepted synonym and swapping offical > option with the synonym, let alone deprecating "--cached". > > You may have heard from several users that they like the word > "staged", but I am sure there are more than several thousand users > who have been using Git since before the synonym was introduced. For sideline readers, some of this is documented in "git help cli" in the "NOTES ON FREQUENTLY CONFUSED OPTIONS" section. -- D. Ben Knoble
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Mon, 09 Nov 2026 20:31
Date: Mon, 09 Nov 2026 20:31
20 lines
13575 bytes
13575 bytes
Jeff King <peff@peff.net> writes: > On Sat, Nov 07, 2026 at 08:35:29PM -0800, Junio C Hamano wrote: > >> An offtopic tangent but didn't we repeatedly float ideas to drop >> support for AsciiDoc, make sure our documentation set renders well >> only with AsciiDoctor, and tell folks who do not use AsciiDoctor to >> use pre-rendered documentation pages from git-htmldocs.git and >> git-manpages.git repositories at https://git.kernel.org/pub/scm/git/ >> during the past several months? > > Yeah, that's what I was hinting at near the bottom of my message. :) > > But it's a big enough change that this series should probably just > accept the ugly syntax for now, rather than waiting for us to drop > python asciidoc support. Yup, agreed. Improvements for these examples do not have to be held hostage on the toolchain support.
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Mon, 09 Nov 2026 22:20
Date: Mon, 09 Nov 2026 22:20
83 lines
15726 bytes
15726 bytes
Jeff King <peff@peff.net> writes: > On Thu, Nov 05, 2026 at 03:40:17PM +0000, Julia Evans via GitGitGadget wrote: > >> +[[name_only]] >> `--name-only`:: >> Show only the name of each changed file in the post-image tree. >> The file names are often encoded in UTF-8. >> For more information see the discussion about encoding in the linkgit:git-log[1] >> manual page. > > Sadly this syntax seems to work with Asciidoctor, but not Asciidoc. The > latter doesn't create the anchors, and then xmlto complaints that the > result doesn't validate. > > Doing it like this works in both: > > `--name-only`[[name_only]]:: > ... > > but...yikes. It's pretty ugly. This of course tempts me in the direction > of ditching python asciidoc support, but I'm not sure if you want to > hold up your series for that. In any case, I'll queue another SQUASH??? commit on top of the topic until v3 materiazlies to fix these issues we have accumulated so far. diff --git c/Documentation/diff-options.adoc w/Documentation/diff-options.adoc index 2dc54fa00e..bb46fd065b 100644 --- c/Documentation/diff-options.adoc +++ w/Documentation/diff-options.adoc @@ -201,8 +201,7 @@ diff" algorithm internally. include::diff-algorithm-option.adoc[] -[[stat]] -`--stat[=<width>[,<name-width>[,<count>]]]`:: +`--stat[=<width>[,<name-width>[,<count>]]]`[[stat]]:: Generate a diffstat. By default, as much space as necessary will be used for the filename part, and the rest for the graph part. Maximum width defaults to terminal width, or 80 columns @@ -319,15 +318,13 @@ Without this option, pathnames with "unusual" characters are quoted as explained for the configuration variable `core.quotePath` (see linkgit:git-config[1]). -[[name_only]] -`--name-only`:: +`--name-only`[[name_only]]:: Show only the name of each changed file in the post-image tree. The file names are often encoded in UTF-8. For more information see the discussion about encoding in the linkgit:git-log[1] manual page. -[[name_status]] -`--name-status`:: +`--name-status`[[name_status]]:: Show only the name(s) and status of each changed file. See the description of the `--diff-filter` option on what the status letters mean. Just like `--name-only` the file names are often encoded in UTF-8. @@ -420,8 +417,7 @@ endif::git-diff[] Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent. -[[ignore_all_space]] -`ignore-all-space`:: +`ignore-all-space`[[ignore_all_space]]:: Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none. `allow-indentation-change`:: @@ -436,8 +432,7 @@ endif::git-diff[] used to override configuration settings. It is the same as `--color-moved-ws=no`. -[[word_diff]] -`--word-diff[=<mode>]`:: +`--word-diff[=<mode>]`[[word_diff]]:: By default, words are delimited by whitespace; see `--word-diff-regex` below. The _<mode>_ defaults to `plain`, and must be one of:
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Mon, 09 Nov 2026 22:40
Date: Mon, 09 Nov 2026 22:40
60 lines
14920 bytes
14920 bytes
Junio C Hamano <gitster@pobox.com> writes:
> Jeff King <peff@peff.net> writes:
>
>> On Thu, Nov 05, 2026 at 03:40:17PM +0000, Julia Evans via GitGitGadget wrote:
>>
>>> +[[name_only]]
>>> `--name-only`::
>>> Show only the name of each changed file in the post-image tree.
>>> The file names are often encoded in UTF-8.
>>> For more information see the discussion about encoding in the linkgit:git-log[1]
>>> manual page.
>>
>> Sadly this syntax seems to work with Asciidoctor, but not Asciidoc. The
>> latter doesn't create the anchors, and then xmlto complaints that the
>> result doesn't validate.
>>
>> Doing it like this works in both:
>>
>> `--name-only`[[name_only]]::
>> ...
>>
>> but...yikes. It's pretty ugly. This of course tempts me in the direction
>> of ditching python asciidoc support, but I'm not sure if you want to
>> hold up your series for that.
>
> In any case, I'll queue another SQUASH??? commit on top of the topic
> until v3 materiazlies to fix these issues we have accumulated so
> far.
And I realized that we need yet another SQUASH to address "isn't it
a value of another option?" point.
SQUASH???
it is likely that the annotation was meant to go with --dashed-option
diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc
index bb46fd065b..dbac3b8275 100644
--- a/Documentation/diff-options.adoc
+++ b/Documentation/diff-options.adoc
@@ -417,7 +417,7 @@ endif::git-diff[]
Ignore changes in amount of whitespace. This ignores whitespace
at line end, and considers all other sequences of one or
more whitespace characters to be equivalent.
-`ignore-all-space`[[ignore_all_space]]::
+`ignore-all-space`::
Ignore whitespace when comparing lines. This ignores differences
even if one line has whitespace where the other line has none.
`allow-indentation-change`::
@@ -783,7 +783,7 @@ endif::git-format-patch[]
more whitespace characters to be equivalent.
`-w`::
-`--ignore-all-space`::
+`--ignore-all-space`[[ignore_all_space]]::
Ignore whitespace when comparing lines. This ignores
differences even if one line has whitespace where the other
line has none.
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Kaartic Sivaraam
Date: Tue, 10 Nov 2026 15:25
Date: Tue, 10 Nov 2026 15:25
30 lines
12213 bytes
12213 bytes
On 11/10/26 19:16, Julia Evans wrote: > > On Mon, Nov 9, 2026, at 5:40 PM, Junio C Hamano wrote: >> Junio C Hamano <gitster@pobox.com> writes: >>> >>> In any case, I'll queue another SQUASH??? commit on top of the topic >>> until v3 materiazlies to fix these issues we have accumulated so >>> far. > > Thanks for this, I don't know how to apply a patch from an email but > I'll ask in the Discord to try to learn how. Same for the other changes. As mentioned in Discord, when Junio mentions something along the lines of "I'll queue another SQUASH??? commit" , it means he would've already queued the SQUASH commit in the topic branch in his tree. You can view the same using something like: $ git remote add jch https://github.com/gitster/git $ git fetch jch je/doc-git-diff-examples $ git log FETCH_HEAD Then on your local topic branch, you can do: $ git cherry-pick --no-commit <List_of_SQUASH_commit_ID...> Hope this helps. -- Sivaraam
Re: [PATCH v2] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Tue, 10 Nov 2026 17:22
Date: Tue, 10 Nov 2026 17:22
9 lines
13086 bytes
13086 bytes
"Julia Evans" <julia@jvns.ca> writes:
> Thanks for this, I don't know how to apply a patch from an email but
> I'll ask in the Discord to try to learn how. Same for the other changes.
It might be easier to fetch from me, find these squash commits from
'seen' ("git log seen" is your friend), and cherry pick them on top
of what you have.
[PATCH v3] doc: git-diff: rewrite EXAMPLES section
Author: "Julia Evans via GitGitGadget"
Date: Wed, 11 Nov 2026 20:13
Date: Wed, 11 Nov 2026 20:13
384 lines
25905 bytes
25905 bytes
From: Julia Evans <julia@jvns.ca>
The top piece of feedback users always give about man pages is always
that they want better examples that are relevant to them.
The EXAMPLES section's structure has remained mostly unchanged since
2007, which was before we knew how people were going to use `git diff`.
Update it with ways of using `git diff` that are popular with Git
users, gathered by asking Mastodon users for their most commonly used
incantations. Keep the example that was added since 2007
(`git diff AUTO_MERGE`), rewording it to use the more familiar term
"merge conflict" instead of "textual conflict".
Add a note about the EXAMPLES section in the DESCRIPTION since otherwise
readers are unlikely to know it's there. `git diff` is a command where
it's more important than usual to have examples because the command has
so many different forms.
Some design choices:
- Mention both `git diff --staged` and `git diff --cached`, because
"staged" is the term the Git user interface uses and several users
said they find it easier to understand. Add an entry for --staged
saying that it's a synonym. Like with `git switch`, and `git checkout`
it's useful to leave the older version for folks who are used to using
`git diff --cached` since we've seen that many people who are used to
using a command don't see any value in changing how they use it.
- Use a definition list for the examples instead of the footnote style,
so that the description and the example are right next to each other
and it's easier to read.
- Use `--merge-base` instead of `...` since several users said they
find .. vs ... confusing. It's much more obvious what --merge-base
does.
- Link the options in the examples to make them faster to look up
- Use sub-subsection headings for the different parts to make
them more visually distinct and easy to scan.
Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Julia Evans <julia@jvns.ca>
---
doc: git-diff: rewrite EXAMPLES section
changes in v2:
* Switch from tables to a definition list, to avoid wrapping but still
staying relatively compact.
* Mention git diff --cached alongside git diff --staged so folks can
use whichever version they prefer, and update the commit message with
some notes about that. It's an example of one of many situations in
Git where what's best to recommend for new users and what's best for
long-term users is not necessarily the same.
* Put back AUTO_MERGE (thanks to Junio for pointing out that it was
added much more recently than all the rest of the examples)
changes in v3:
* Remove the changes to --cached/--staged in the SYNOPSIS and
DESCRIPTION.
* Squash the formatting changes from Junio for the links.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2293%2Fjvns%2Fdiff-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2293/jvns/diff-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/2293
Range-diff vs v2:
1: ec565ce334 ! 1: 899def065e doc: git-diff: rewrite EXAMPLES section
@@ Documentation/diff-options.adoc: diff" algorithm internally.
include::diff-algorithm-option.adoc[]
-+[[stat]]
- `--stat[=<width>[,<name-width>[,<count>]]]`::
+-`--stat[=<width>[,<name-width>[,<count>]]]`::
++`--stat[=<width>[,<name-width>[,<count>]]]`[[stat]]::
Generate a diffstat. By default, as much space as necessary
will be used for the filename part, and the rest for the graph
+ part. Maximum width defaults to terminal width, or 80 columns
@@ Documentation/diff-options.adoc: Without this option, pathnames with "unusual" characters are quoted as
explained for the configuration variable `core.quotePath` (see
linkgit:git-config[1]).
-+[[name_only]]
- `--name-only`::
+-`--name-only`::
++`--name-only`[[name_only]]::
Show only the name of each changed file in the post-image tree.
The file names are often encoded in UTF-8.
For more information see the discussion about encoding in the linkgit:git-log[1]
manual page.
-+[[name_status]]
- `--name-status`::
+-`--name-status`::
++`--name-status`[[name_status]]::
Show only the name(s) and status of each changed file. See the description
of the `--diff-filter` option on what the status letters mean.
-@@ Documentation/diff-options.adoc: endif::git-diff[]
- Ignore changes in amount of whitespace. This ignores whitespace
- at line end, and considers all other sequences of one or
- more whitespace characters to be equivalent.
-+[[ignore_all_space]]
- `ignore-all-space`::
- Ignore whitespace when comparing lines. This ignores differences
- even if one line has whitespace where the other line has none.
+ Just like `--name-only` the file names are often encoded in UTF-8.
@@ Documentation/diff-options.adoc: endif::git-diff[]
used to override configuration settings. It is the same as
`--color-moved-ws=no`.
-+[[word_diff]]
- `--word-diff[=<mode>]`::
+-`--word-diff[=<mode>]`::
++`--word-diff[=<mode>]`[[word_diff]]::
By default, words are delimited by whitespace; see
`--word-diff-regex` below. The _<mode>_ defaults to `plain`, and
+ must be one of:
+@@ Documentation/diff-options.adoc: endif::git-format-patch[]
+ more whitespace characters to be equivalent.
+
+ `-w`::
+-`--ignore-all-space`::
++`--ignore-all-space`[[ignore_all_space]]::
+ Ignore whitespace when comparing lines. This ignores
+ differences even if one line has whitespace where the other
+ line has none.
## Documentation/git-diff.adoc ##
-@@ Documentation/git-diff.adoc: SYNOPSIS
- --------
- [synopsis]
- git diff [<options>] [<commit>] [--] [<path>...]
--git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]
-+git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...]
- git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]
- git diff [<options>] <commit>...<commit> [--] [<path>...]
- git diff [<options>] <blob> <blob>
@@ Documentation/git-diff.adoc: between the index and a tree, changes between two trees, changes resulting
from a merge, changes between two blob objects, or changes between two
files on disk.
@@ Documentation/git-diff.adoc: between the index and a tree, changes between two t
`git diff [<options>] [--] [<path>...]`::
This form is to view the changes you made relative to
-@@ Documentation/git-diff.adoc: files on disk.
- difference. All such pathspecs must be relative as they
- apply to both sides of the diff.
-
--`git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]`::
-+`git diff [<options>] --staged [--merge-base] [<commit>] [--] [<path>...]`::
-
- This form is to view the changes you staged for the next
- commit relative to the named _<commit>_. Typically you
-@@ Documentation/git-diff.adoc: files on disk.
- do not give _<commit>_, it defaults to `HEAD`.
- If `HEAD` does not exist (e.g. unborn branches) and
- _<commit>_ is not given, it shows all staged changes.
-- `--staged` is a synonym of `--cached`.
-+ `--cached` is a synonym of `--staged`.
- +
- If `--merge-base` is given, instead of using _<commit>_, use the merge base
- of _<commit>_ and `HEAD`. `git diff --cached --merge-base A` is equivalent to
--`git diff --cached $(git merge-base A HEAD)`.
-+`git diff --staged $(git merge-base A HEAD)`.
-
- `git diff [<options>] [--merge-base] <commit> [--] [<path>...]`::
-
@@ Documentation/git-diff.adoc: section "3-Way Merge" for detailed information.
include::diff-format.adoc[]
Documentation/diff-options.adoc | 10 +--
Documentation/git-diff.adoc | 132 ++++++++++++++++----------------
2 files changed, 70 insertions(+), 72 deletions(-)
diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc
index e605d28678..dbac3b8275 100644
--- a/Documentation/diff-options.adoc
+++ b/Documentation/diff-options.adoc
@@ -201,7 +201,7 @@ diff" algorithm internally.
include::diff-algorithm-option.adoc[]
-`--stat[=<width>[,<name-width>[,<count>]]]`::
+`--stat[=<width>[,<name-width>[,<count>]]]`[[stat]]::
Generate a diffstat. By default, as much space as necessary
will be used for the filename part, and the rest for the graph
part. Maximum width defaults to terminal width, or 80 columns
@@ -318,13 +318,13 @@ Without this option, pathnames with "unusual" characters are quoted as
explained for the configuration variable `core.quotePath` (see
linkgit:git-config[1]).
-`--name-only`::
+`--name-only`[[name_only]]::
Show only the name of each changed file in the post-image tree.
The file names are often encoded in UTF-8.
For more information see the discussion about encoding in the linkgit:git-log[1]
manual page.
-`--name-status`::
+`--name-status`[[name_status]]::
Show only the name(s) and status of each changed file. See the description
of the `--diff-filter` option on what the status letters mean.
Just like `--name-only` the file names are often encoded in UTF-8.
@@ -432,7 +432,7 @@ endif::git-diff[]
used to override configuration settings. It is the same as
`--color-moved-ws=no`.
-`--word-diff[=<mode>]`::
+`--word-diff[=<mode>]`[[word_diff]]::
By default, words are delimited by whitespace; see
`--word-diff-regex` below. The _<mode>_ defaults to `plain`, and
must be one of:
@@ -783,7 +783,7 @@ endif::git-format-patch[]
more whitespace characters to be equivalent.
`-w`::
-`--ignore-all-space`::
+`--ignore-all-space`[[ignore_all_space]]::
Ignore whitespace when comparing lines. This ignores
differences even if one line has whitespace where the other
line has none.
diff --git a/Documentation/git-diff.adoc b/Documentation/git-diff.adoc
index 272331afba..f7489a0da9 100644
--- a/Documentation/git-diff.adoc
+++ b/Documentation/git-diff.adoc
@@ -23,6 +23,9 @@ between the index and a tree, changes between two trees, changes resulting
from a merge, changes between two blob objects, or changes between two
files on disk.
+The <<EXAMPLES,EXAMPLES>> section has examples of the most common ways
+to diff.
+
`git diff [<options>] [--] [<path>...]`::
This form is to view the changes you made relative to
@@ -160,78 +163,73 @@ section "3-Way Merge" for detailed information.
include::diff-format.adoc[]
+[[EXAMPLES]]
EXAMPLES
--------
-Various ways to check your working tree::
-+
-------------
-$ git diff <1>
-$ git diff --cached <2>
-$ git diff HEAD <3>
-$ git diff AUTO_MERGE <4>
-------------
-+
-<1> Changes in the working tree not yet staged for the next commit.
-<2> Changes between the index and your last commit; what you
- would be committing if you run `git commit` without `-a` option.
-<3> Changes in the working tree since your last commit; what you
- would be committing if you run `git commit -a`
-<4> Changes in the working tree you've made to resolve textual
- conflicts so far.
-
-Comparing with arbitrary commits::
-+
-------------
-$ git diff test <1>
-$ git diff HEAD -- ./test <2>
-$ git diff HEAD^ HEAD <3>
-------------
-+
-<1> Instead of using the tip of the current branch, compare with the
- tip of "test" branch.
-<2> Instead of comparing with the tip of "test" branch, compare with
- the tip of the current branch, but limit the comparison to the
- file "test".
-<3> Compare the version before the last commit and the last commit.
-
-Comparing branches::
-+
-------------
-$ git diff topic master <1>
-$ git diff topic..master <2>
-$ git diff topic...master <3>
-------------
-+
-<1> Changes between the tips of the topic and the master branches.
-<2> Same as above.
-<3> Changes that occurred on the master branch since when the topic
- branch was started off it.
+Diff uncommitted changes
+~~~~~~~~~~~~~~~~~~~~~~~~
-Limiting the diff output::
-+
-------------
-$ git diff --diff-filter=MRC <1>
-$ git diff --name-status <2>
-$ git diff arch/i386 include/asm-i386 <3>
-------------
-+
-<1> Show only modification, rename, and copy, but not addition
- or deletion.
-<2> Show only names and the nature of change, but not actual
- diff output.
-<3> Limit diff output to named subtrees.
+Show unstaged changes::
+`git diff`
-Munging the diff output::
-+
-------------
-$ git diff --find-copies-harder -B -C <1>
-$ git diff -R <2>
-------------
-+
-<1> Spend extra cycles to find renames, copies and complete
- rewrites (very expensive).
-<2> Output diff in reverse.
+Show staged changes::
+`git diff --staged` or `git diff --cached`
+
+Show all changes since the latest commit::
+`git diff HEAD`
+
+Show changes made to resolve a merge conflict::
+`git diff AUTO_MERGE`
+
+Diff a specific file/directory
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can usually put a filename or directory at the end to restrict the
+diff to that file/directory. You don't always need to put a `--`, but it
+makes it unambiguous.
+
+Show how `file.txt` has changed since `main`::
+`git diff main -- file.txt`
+
+Show unstaged changes for `file.txt`::
+`git diff -- file.txt`
+
+Show unstaged changes in `dir/`::
+`git diff -- ./dir`
+
+Diff branches or commits
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Show changes on the `topic` branch since it branched off `main`::
+`git diff --merge-base main topic`
+
+Show changes between the `topic` branch and the `main` branch::
+`git diff main topic`
+
+Show changes between commit `ff11cc` and `HEAD`::
+`git diff ff11cc HEAD`
+
+Options to summarize the output
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Show how many lines in each file were changed::
+`git diff` <<stat,`--stat`>>
+
+Only show names of changed files::
+`git diff` <<name_only,`--name-only`>>
+
+Only show filenames and whether they were modified/deleted/added::
+`git diff` <<name_status,`--name-status`>>
+
+Options to display the diff in another way
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Ignore all whitespace changes::
+`git diff` <<ignore_all_space,`--ignore-all-space`>>
+
+Show which individual words changed instead of the whole line::
+`git diff` <<word_diff,`--word-diff`>>
CONFIGURATION
-------------
base-commit: 0ffa3e35c7c82ab8d0de226149fb03b3f7674d05
--
gitgitgadget
Re: [PATCH v3] doc: git-diff: rewrite EXAMPLES section
Author: Junio C Hamano
Date: Wed, 11 Nov 2026 21:52
Date: Wed, 11 Nov 2026 21:52
17 lines
13433 bytes
13433 bytes
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Julia Evans <julia@jvns.ca> > > The top piece of feedback users always give about man pages is always > that they want better examples that are relevant to them. > > The EXAMPLES section's structure has remained mostly unchanged since > 2007, which was before we knew how people were going to use `git diff`. > Update it with ways of using `git diff` that are popular with Git > users, gathered by asking Mastodon users for their most commonly used > incantations. Keep the example that was added since 2007 > (`git diff AUTO_MERGE`), rewording it to use the more familiar term > "merge conflict" instead of "textual conflict". Thanks. Will replace.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads