As noted by biffen in their comment:
--name-status
and --stat
are similar to --name-only
but give a bit more info about each file.
With Git 2.46 (Q3 2024), batch 8, adds details on those commands: the documentation for "git diff --name-only
"(man) has been clarified that it is about showing the names in the post-image tree.
See commit 4986662 (17 May 2024) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
-- in commit 6e95dce, 28 May 2024)
diff
: document what --name-only
shows
The "--name-only
" option is about showing the name of each file in the post-image tree that got changed and nothing else (like "was it created?").
Unlike the "--name-status
" option that tells how the change happened (e.g., renamed with similarity), it does not give anything else, like the name of the corresponding file in the old tree.
For example, if you start from a clean checkout that has a file whose name is COPYING
, here is what you would see:
$ git mv COPYING RENAMING
$ git diff -M --name-only HEAD
RENAMING
$ git diff -M --name-status HEAD
R100 COPYING RENAMING
Lack of the description of this fact has confused readers in the past.
Even back when dda2d79 ("[PATCH]
Clean up diff option descriptions.", 2005-07-13, Git v0.99.1 -- merge) documented "--name-only", "git diff
"(man) already supported the renames, so in a sense, from day one, this should have been documented more clearly but it wasn't.
Belatedly clarify it.
diff-options
now includes in its man page:
Show only the name of each changed file in the post-image tree.
The file names are often encoded in UTF-8.
[...]
Show only the name(s) and status of each changed file.
The post-image tree is an important concept because --name-only
shows the file names as they appear after the changes have been applied. This means that if a file was renamed, only the new name is shown.
As shown in the commit above:
git mv COPYING RENAMING
git diff -M --name-only HEAD
Output:
RENAMING
Here, RENAMING
is the file name in the post-image tree.
More details: git diff --name-status origin/YourBranch YourBranch
You would get:
A newfile.txt
M modifiedfile.txt
D deletedfile.txt
R100 COPYING RENAMING
git diff --name-only commit1 commit2
– Austin