如果将其通过管道传输到 more,为什么 git log 中的 git 分支和标记注释会消失?

发布于 2025-01-13 08:45:36 字数 1124 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2025-01-20 08:45:36

手册页 git-log(1) (自版本 3.33 起)解释了默认值--decorate 的行为是 auto,并且无论您是否在终端中运行,它的作用都会改变:

   --no-decorate, --decorate[=short|full|auto|no]
       <...>
       If auto is specified, then if the output is going to a terminal, the ref
       names are shown as if short were given, otherwise no ref names are shown.
       <...>
       Default to configuration value of log.decorate if configured, otherwise,
       auto.
       

当您运行一个输出上带有管道的程序时,输出将成为管道本身,而不是终端,因此不会显示引用名称。

The manual page git-log(1) (since version 3.33) explains that the default behaviour for --decorate is auto, and what it does changes whether you are running in a terminal or not:

   --no-decorate, --decorate[=short|full|auto|no]
       <...>
       If auto is specified, then if the output is going to a terminal, the ref
       names are shown as if short were given, otherwise no ref names are shown.
       <...>
       Default to configuration value of log.decorate if configured, otherwise,
       auto.
       

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文