John Cheng
John Cheng

Reputation: 569

What is the effect of git diff-files --diff-filters=A?

The documentation for git-diff-files(1) says

Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, …) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B)...

However, the following commands do not show the added file (don't run this in a directory with an origin subdirectory):

start=$PWD
origin="$start/origin"

rm -rf $origin
mkdir $origin
cd $origin
touch 1.txt
echo "2" > 2.txt
git init
git add -A
git commit -m "init"

echo "1" > 1.txt
rm 2.txt
echo "3" > 3.txt
git diff-files --diff-filter=ADM

The output looks like:

$ git diff-files --diff-filter=ADM
:100644 100644 e69de... 0000... M      1.txt
:100644 000000 0cfbf... 0000... D      2.txt

Does git diff-files never show added files? The diff-filter option suggests that it is capable of selecting added files.

Upvotes: 2

Views: 2646

Answers (1)

mmlr
mmlr

Reputation: 2155

Indeed git diff-files will never show added files.

The diff-files command shows the difference between the index and the files in the working copy. By definition a file that wasn't added to the index yet (via git add) will not be part of the index and can therefore not show up in any diff between the index and the working copy. Just adding the file to the index will make the file identical in the index and the working copy, hence it will not have any difference between the index and working copy and therefore not show up in diff-files either. Modifying an added file in the working copy will then directly result in the M state.

The reason that the documentation shows all of the possible --diff-filter arguments is that the diff options documentation is shared among all of the commands that take diff options (diff-files, diff-index, diff-tree, format-patch, log and show). Their respective documentation simply includes the diff-options documentation:

include::diff-options.txt[]

Seen in this line of the git-diff-files documentation source for example. The common diff-options then has the shared --diff-filter text starting here.

Since these files are processed when the documentation is built, as evidenced by the conditional

ifndef::git-format-patch[]

in the line above the --diff-filter documentation, the text could conceivably be varied for the diff-files command (or augmented to state the fact that some arguments do not apply). Opening a bug report to the git project for this change may make sense.

Upvotes: 3

Related Questions