制作git diff --stat显示完整的文件路径

Bad*_*dri 94 git git-diff

在做git diff --stat一些文件时列出了来自存储库库的完整路径,但有些文件列为:

.../short/path/to/filename.  
Run Code Online (Sandbox Code Playgroud)

这是路径开始,...只显示短路径.

我想git diff列出所有文件的完整文件路径,以便脚本轻松处理.有什么方法可以让我git diff总是显示完整的路径

tor*_*rek 98

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>.
Run Code Online (Sandbox Code Playgroud)

(对于脚本,你可能想git diff-tree直接使用,因为它更像是一个"管道"命令,虽然我怀疑你会很好.请注意你--stat在使用时需要相同的额外文本git diff-tree.使用git diff"瓷器" 之间的本质区别"前端和git diff-tree管道命令,是git diff查找已配置的选项,diff.renames以决定是否进行重命名检测.好吧,如果您将提交与索引进行比较git diff,git diff-index那么加上前端将完成相同的操作例如.换句话说,git diff 读取您的配置自动调用正确的管道.)

  • git diff --numstat与diff-tree相同 (6认同)
  • 有没有办法全球化这个?每次打字都很疯狂. (4认同)

cmb*_*ley 17

对于脚本处理,最好使用以下方法之一:

# 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
Run Code Online (Sandbox Code Playgroud)

当与作为字段终止符的-z选项结合使用时,这些对于强大的脚本处理变得更加方便NUL.


Joh*_*lor 15

对于Bash用户,您可以使用该$COLUMNS变量自动填充可用的终端宽度:

git diff --stat=$COLUMNS
Run Code Online (Sandbox Code Playgroud)

很长的路径名称可能仍会被截断; 在这种情况下,您可以使用缩小+++/---部分的宽度--stat-graph-width,例如,这会将其限制为终端宽度的1/5:

git show --stat=$COLUMNS --stat-graph-width=$(($COLUMNS/5))
Run Code Online (Sandbox Code Playgroud)

对于更通用的解决方案,您可以使用输出tput cols来确定终端宽度.

  • 有没有办法全球化`--stat = $ COLUMNS,$ COLUMNS`?每次打字都很疯狂. (2认同)
  • @ user151841当然,但合并已经给出了统计摘要.没有参数/配置.如果所有'stat summary'都使用相同的配置,那就太棒了. (2认同)

Yev*_*iuk 8

有一个选择--name-onlygit diff --name-only。其他 git 命令也支持该选项,例如showstash

该选项不会缩短路径。