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

标签 bash git

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

相关文章:

git - 将忽略的文件保留在 git status 之外

git - 关于失败的 GitHub WebHooks 的通知?

windows - Windows批处理文件中的git grep和xargs?

linux - Bash - 从零开始的 Linux,cheching 库脚本

linux - 如何检查bash命令是否在后台运行?

string - 解析字符串以查找可能引用的字段的通用 shell/bash 方法?

git - 为什么 git 不给我任何冲突?

linux - Bash - 将带有反斜杠的用户名回显到文件

linux - 根据内容将文件分类到文件夹的 Bash 脚本;如何解决变量中的通配符?

java - GIT:如何使用cherry-pick在两个分支中提交