如果将其通过管道传输到 more,为什么 git log 中的 git 分支和标记注释会消失?
git version 2.20.1
(base) piadmin@pi-spec1:~/pi$ git log
commit 2851703321fd8d026c51621dd9553f2cec92a6c0 (HEAD -> PI_InFactory, tag: PI_shipped_20220310, origin/PI_InFactory)
Author: David <[email protected]>
Date: Thu Mar 10 10:08:34 2022 -0500
Fix classes to match PI, on commented line, for agile customer support
(base) piadmin@pi-spec1:~/pi$ git log | more -20
commit 2851703321fd8d026c51621dd9553f2cec92a6c0
Author: David <[email protected]>
Date: Thu Mar 10 10:08:34 2022 -0500
Fix classes to match PI, on commented line, for agile customer support
请注意,当我使用“more”时,“commit”行上缺少什么?
澄清编辑:当我问“为什么”时,是因为在我数十年的 Linux 经验中,当将某些内容通过管道传输到 more
时,我从未见过输出变化(除了颜色丢失)。在我看来,这就像命令行 *nix 和管道架构的基本概念,这不可能发生,所以我想我的意思是“如何?”和“为什么?”。
在 @LeonardoDagnino 的回答之后,我发现如果我输入 git log --decorate=auto ,我应该期待这种行为,但我没有添加这个参数,帮助说默认选项应该是无论如何,“短”。
git version 2.20.1
(base) piadmin@pi-spec1:~/pi$ git log
commit 2851703321fd8d026c51621dd9553f2cec92a6c0 (HEAD -> PI_InFactory, tag: PI_shipped_20220310, origin/PI_InFactory)
Author: David <[email protected]>
Date: Thu Mar 10 10:08:34 2022 -0500
Fix classes to match PI, on commented line, for agile customer support
(base) piadmin@pi-spec1:~/pi$ git log | more -20
commit 2851703321fd8d026c51621dd9553f2cec92a6c0
Author: David <[email protected]>
Date: Thu Mar 10 10:08:34 2022 -0500
Fix classes to match PI, on commented line, for agile customer support
Notice what's missing on the "commit" line when I used "more"?
Clarification edit: When I ask "why", it's because in my decades of linux experience, I've never seen output change (besides loss of colour) when piping something to more
. It seems to me like a foundational concept of command line *nix, and the pipe architecture, that this cannot happen, so I guess I mean both "how?" and "why?".
After the answer from @LeonardoDagnino, I see that I should expect this behaviour if I typed git log --decorate=auto
, but I am not adding this argument, and the help says the default option should be 'short' anyway.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
手册页 git-log(1) (自版本 3.33 起)解释了默认值
--decorate
的行为是auto
,并且无论您是否在终端中运行,它的作用都会改变:当您运行一个输出上带有管道的程序时,输出将成为管道本身,而不是终端,因此不会显示引用名称。
The manual page git-log(1) (since version 3.33) explains that the default behaviour for
--decorate
isauto
, and what it does changes whether you are running in a terminal or not:When you run a program with a pipe on its output, the output becomes the pipe itself, not a terminal, and as such no ref names are shown.