Answers:
该git diff命令采用以下可选值--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>.
(对于脚本编写,您可能希望git diff-tree直接使用它,因为它更像是“管道”命令,尽管我怀疑您都可以使用。请注意,使用--stat时需要使用相同的额外文本git diff-tree。使用git diff“瓷器” 之间的本质区别”前端,然后使用git diff-tree管道命令git diff查找您配置的设置中的选项,diff.renames以决定是否进行重命名检测。那么,加上前端git diff,git diff-index您将执行的操作相当于将提交与索引进行比较,换句话说,git diff 读取您的配置并自动调用正确的管道。)
--stat-graph-width=...开关。另请注意,将设置为高--stat-graph-width=并--stat-name-width=不够,还必须将其设置为足够--stat-width=大以覆盖两者。
diff.statGraphWidth可用于设置--stat-graph-width值,但其他默认为您的终端宽度。(因此,替代答案:“是的,只是使您的终端窗口宽1000列” :
对于脚本处理,最好使用以下一种方法:
# 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
当与用作字段终止符的-z选项结合使用时,它们对于健壮的脚本处理将变得更加方便NUL。
git rev-parse --show-toplevel。最初的问题是指向截断的路径,这在diffstats中是一个问题,特别是对于长文件名或较低的--stat-name-width。上面的命令不会截断路径,但是会根据请求显示“完整”路径,尽管仍然相对于存储库根目录。
对于Bash用户,您可以使用$COLUMNS变量自动填充可用的终端宽度:
git diff --stat=$COLUMNS
很长的路径名可能仍会被截断;在这种情况下,您可以使用来减小+++ / ---部分的宽度--stat-graph-width,例如,将其限制为端子宽度的1/5:
git show --stat=$COLUMNS --stat-graph-width=$(($COLUMNS/5))
对于更通用的解决方案,您可以使用输出tput cols来确定端子宽度。
--stat=$COLUMNS,$COLUMNS吗?每次输入都是疯狂的。
export COLUMNS到您的~/.bashrc,并在您的~/.gitconfig下面[alias]添加smart-diff = ! "gitsmartdiff() { git diff $2 --stat=$COLUMNS,$COLUMNS; }; gitsmartdiff"
diff。我希望它也适用于合并和拉取等。(甚至不能在那里手动进行。)我不认为GIT支持它。
有一个选择--name-only:git diff --name-only。其他git命令(例如show和)也支持该选项stash。
该选项不会缩短路径。
我发现一个简单的解决方案是执行此操作:(仅适用于* nix,对不起,没有osx)
git diff --stat=$COLUMNS --relative | head -n -1 | cut -c 2- | xargs -d '\n' -P4 printf "$(pwd)/%s\n"
这个版本对两者都适用,但是在osx上看起来并不好。
git diff --stat=$COLUMNS --relative | sed -e '$ d' | cut -c 2- | xargs -n4 -I{} echo "$(pwd)/{}"