在执行git diff --stat时,某些文件会列出存储库基础的完整路径,但有些文件会列出如下所示:
.../short/path/to/filename. 也就是说,路径以...开头,并且只显示短路径。
我想git diff列出的所有文件的完整文件路径,以便它可以很容易地由脚本处理。是否有什么方法可以让git diff始终显示完整路径
发布于 2014-02-12 18:05:39
对于脚本处理,最好使用以下方法之一:
# 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当与使用NUL作为字段终止符的-z选项结合使用时,这些方法对于健壮的脚本处理变得更加方便。
发布于 2013-05-24 18:54:15
对于Bash用户,您可以使用$COLUMNS变量自动填充可用的终端宽度:
git diff --stat=$COLUMNS很长的路径名可能仍然会被截断;在这种情况下,您可以使用--stat-graph-width减少+/-部分的宽度,例如,这会将其限制为终端宽度的1/5:
git show --stat=$COLUMNS --stat-graph-width=$(($COLUMNS/5))对于更通用的解决方案,您可以使用tput cols的输出来确定终端宽度。
发布于 2018-12-30 09:28:20
有一个选项--name-only:git diff --name-only。show和stash等其他git命令也支持该选项。
路径不会因为选项而缩短。
https://stackoverflow.com/questions/10459374
复制相似问题