Create git diff --stat show full path to file

When running git diff --stat some files are listed with the full path from the repository database, but some files are listed as:

 .../short/path/to/filename. 

This path starts with ... and only a short path is displayed.

I would like git diff display the full file path for all files so that it can be easily processed using a script. Is there a way to get git diff to always show the full path

+90
git git-diff
May 05 '12 at 6:11
source share
7 answers

The git diff accepts optional values ​​for --stat :

 --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 scripts, you can use git diff-tree directly because it looks more like a plumbing command, although I suspect that everything will be okay with you. Note that you need the same extra text with --stat when using git diff-tree significant difference between using the front end of git diff china and the t23> plumbing command is that git diff looks at your configured options for options like diff.renames to decide whether to rename. By the way, plus the front end git diff will do the equivalent There is a git diff-index if you are comparing a commit to an index, for example, in other words, git diff reads your configuration and automatically invokes the correct automatic plumbing.)

+94
May 5 '12 at 8:26
source share

For script processing, it may be better to use one of the following values:

 # 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 

Each of them becomes more convenient for reliable script processing in combination with the -z option, which uses NUL as field terminators.

+16
Feb 12 '14 at 10:05
source share

For Bash users, you can use the $COLUMNS to automatically fill in the available terminal width:

 git diff --stat=$COLUMNS 

Very long path names can be truncated; in this case, you can reduce the width of the +++ / --- part using --stat-graph-width , for example, this limits it to 1/5 of the terminal width:

 git show --stat=$COLUMNS --stat-graph-width=$(($COLUMNS/5)) 

For a more general solution, you can use the output of tput cols to determine the width of the terminal.

+15
May 24 '13 at 10:54
source share

There is an option --name-only : git diff --name-only . This option is also supported by other git commands such as show and stash .

Paths are not shortened with the option.

+3
Dec 30 '18 at 1:28
source share

I created the following git alias:

 diffstat = ! "gitdiffstat() { git diff --stat=$(tput cols) ${1:-master} ; }; gitdiffstat" 

Reads the number of columns from the tput cols . By default, it is different from master , but you can specify a different branch if you wish.

 $ git diffstat .gitalias | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 
0
Apr 22 '19 at 14:44
source share

I found a simple solution: (only works on * nix, sorry no osx)

 git diff --stat=$COLUMNS --relative | head -n -1 | cut -c 2- | xargs -d '\n' -P4 printf "$(pwd)/%s\n" 

This version works for both, but on osx it doesn't look very good.

 git diff --stat=$COLUMNS --relative | sed -e '$ d' | cut -c 2- | xargs -n4 -I{} echo "$(pwd)/{}" 
0
Aug 13 '19 at 12:27
source share

I found that the behavior of diff -stat changed somewhere around git 1.7.10, where earlier it defaulted to shortening file paths to a fixed width - now it displays as much as the terminal window allows. If you are having this problem, make sure you are upgrading to version 1.8.0 or later.

-one
Feb 18 '13 at 16:51
source share



All Articles