当我在没有管道或文件重定向的情况下执行 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/