gpt4 book ai didi

bash - git log --oneline 提供在管道或重定向到文件时丢失的 HEAD 信息

转载 作者:太空狗 更新时间:2023-10-29 14:41:23 25 4
gpt4 key购买 nike

当我在没有管道或文件重定向的情况下执行 git log --oneline 命令时,它会提供有关 HEAD 位置和分支的信息(在下面的示例中为 master)

 $ git log --oneline --color=never

8bc8511 (HEAD -> day_20190316) Today # 12
1381438 Today # 11
d87d53a Today # 10
718aef9 Today # 9
b05e17e Today # 8
....
2643d93 (master) Initial commit

但是,当我通过 less 将其通过管道传输或将其重定向到文件中时,HEAD 和 master 信息就会消失。我试过重定向 stderr 以加入 stdout,但这没有任何区别。

$ git log --oneline --color=never 2>&1 |/usr/bin/更多

8bc8511 Today # 12
1381438 Today # 11
d87d53a Today # 10
718aef9 Today # 9
b05e17e Today # 8
.....
2643d93 Initial commit

我想访问该信息,但是如何访问?

最佳答案

使用--decorate标志

git log --oneline --decorate --color=never | less

来自 the git docs

--decorate[=short|full|auto|no]

Print out the ref names of any commits that are shown. If short is specified, the ref name prefixes refs/heads/, refs/tags/ and refs/remotes/ will not be printed. If full is specified, the full ref name (including prefix) will be printed. 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. The option --decorate is short-hand for --decorate=short. Default to configuration value of log.decorate if configured, otherwise, auto.

未指定 --decorate 时默认为自动,意思是“如果转到终端则添加 HEAD 信息,否则不添加”。当您在没有参数的情况下指定 --decorate 时,它默认为 short,这是您在问题中引用的短 HEAD 信息。

关于bash - git log --oneline 提供在管道或重定向到文件时丢失的 HEAD 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55203481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com