git - 如何在管道传输时配置 git 输出?

标签 git bash pipe

我注意到如果你这样做

$ git diff -M --stat
out_of_the_water/out_of_itself => he_watches_my_gauze_dress/blowing_on_the_line | 0
1 file changed, 0 insertions(+), 0 deletions(-)

$ git diff -M --stat | cat 
.../out_of_itself => he_watches_my_gauze_dress/blowing_on_the_line        | 0
1 file changed, 0 insertions(+), 0 deletions(-)

输出不同,第一个文件名被截断。这对我来说是一个问题,因为我想隔离两个文件名:

$ git diff -M head~1 --stat | perl -ne 'print "$1 $2" if m/^\s*(.*?) => (.*?) \|/'

如果通过管道传输到另一个进程,如何配置 git 提供相同的输出?

最佳答案

我很想说 RTFM,但为了您的利益,我将在此处引用相关部分:

--stat[=<width>[,<name-width>[,<count>]]]

Generate a diffstat. By default, as much space as necessary will be used for the filename part, and the rest for the graph part. Maximum width defaults to terminal width, or 80 columns if not connected to a terminal, and can be overridden by <width>. The width of the filename part can be limited by giving another width <name-width> after a comma. The width of the graph part can be limited by using --stat-graph-width=<width> (affects all commands generating a stat graph) or by setting diff.statGraphWidth=<width> (does not affect git format-patch). 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>.

所以如果没有管道,宽度就是你的终端宽度,比80个字符宽;对于管道,没有终端宽度,因此宽度为 80。因此只需使用 --stat=99999并且任何内容都不应该被缩写。

关于git - 如何在管道传输时配置 git 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41280494/

相关文章:

c++ - 如何正确接收来自管道的数据?

git - 如何更改 Git 上游的提交日期?

git - 无法锁定引用 'refs/remotes/origin/master'

linux - 如何使用 bash 提取特定日期和时间的 UTC 偏移量?

c - 使用两个子进程在我自己的 shell 中实现管道

c - 通过管道读写数据

git - git svn fetch 错误 : svn-remote "svn" unknown

git - 如何确定 Git 是将文件处理为二进制文件还是文本文件?

linux - 需要读取文件并将结果用作 shell 脚本中的命名变量

linux - 我怎样才能得到下个月的 shell ?