Making git diff --stat show full file path
For script processing, it might be better to use one of the following:
# list just the file names
git diff --name-only
path/to/modified/file
path/to/renamed/file
# list the names and change statuses:
git diff --name-status
M path/to/modified/file
R100 path/to/existing/file path/to/renamed/file
# list a diffstat-like output (+ed lines, -ed lines, file name):
git diff --numstat
1 0 path/to/modified/file
0 0 path/to/{existing => renamed}/file
These each become more handy for robust script processing when combined with the -z
option, which uses NUL
as the field terminators.
By default git diff
truncates its output to fit into a 80-column terminal.
You can override this by specifying values using the --stat
option:
--stat[=<width>[,<name-width>[,<count>]]]
Generate a diffstat. You can override the default output width for
80-column terminal by --stat=<width>. The width of the filename
part can be controlled by giving another width to it separated by a
comma. By giving a third parameter <count>, you can limit the
output to the first <count> lines, followed by ... if there are
more.
These parameters can also be set individually with
--stat-width=<width>, --stat-name-width=<name-width> and
--stat-count=<count>.
For example, by setting the output value to a very large number:
git diff --stat=10000
Note that produces the path relative to the root of the git repository.
(For scripting you might want to use git diff-tree
directly since it's more of a "plumbing" command, although I suspect you'll be fine either way. Note that you need the same extra text with --stat
when using git diff-tree
. The essential difference between using the git diff
"porcelain" front end, and the git diff-tree
plumbing command, is that git diff
looks up your configured settings for options like diff.renames
to decide whether to do rename detection. Well, that, plus the front end git diff
will do the equivalent of git diff-index
if you're comparing a commit with the index, for instance. In other words, git diff
reads your config and invokes the right plumbing automatically.)