为什么管道会从 git log 中删除分支名称? [英] Why does a pipe remove the branch names from git log?

查看:6

问题描述

当我跑步时

<代码>>git log --oneline

我得到的输出看起来像这样

abcdef0 (head, branch, origin/branch) 注释0987654 不同的评论1234567(不同分支,起源/分支)第三条评论

但是一旦我将输出通过管道传输到任何东西(例如 > git log --oneline | cat),分支名称就消失了

abcdef0 注释0987654 不同的评论1234567 第三条评论

这意味着我不能 grep,或添加行号,或类似的东西.

(它也缺少颜色和 less 样式行为,但我今天不关心这些)

这是我可以通过命令行参数重新启用的功能吗?

解决方案

首先,我也注意到在管道 bash 之后缺少颜色,但是你描述的 decorations(分支和标签名称)消失很奇怪.让我们分别解决它们.

处理分支名称(装饰)本身

--装饰

是它的标志,一次性使用.

对于永久效果,您可以在

关于颜色

不,我不知道它在传递给 bash 时如何/为什么会中断,我会让更高级的用户回答这部分.(正如我所说,就个人而言,我很高兴你问了这个问题,因为我也很想知道这个问题-谢谢 torek!:-))em>

when I run

> git log --oneline

I get output that looks like this

abcdef0 (head, branch, origin/branch) comment
0987654 different comment
1234567 (different-branch, origin/branch) third comment

But as soon as I pipe the output to anything (e.g. > git log --oneline | cat), the branch names are gone

abcdef0 comment
0987654 different comment
1234567 third comment

This means I can't grep, or add line numbers, or anything like that.

(It's also missing the colors and less style behavior, but I don't care about that either way today)

Is this something I can re-enable via a command-line parameter?

解决方案

For start, I too had noticed the lack of colors after a pipe to bash, but what you describe about decorations (branch and tag names) disappearing is odd. Let's adress them separately.

Adressing the branch names (decorations) themselves

--decorate

is the flag for that, for a one-shot use.

For the permanent effect, you can set it in your config

log.decorate true

And for a more specific need, note you can use it in a pretty format, with the placeholder %d, for example :

git log -10 --pretty=format:"%C(yellow)%h %C(reset)%aN %ar %C(red)%d %C(reset)%s"

for a result that looks like this

About colors

No, I don't know how / why it breaks when it's passed to bash, I'll let more advanced users answer that part. (and as I said, on a personal note I'm very glad you asked this question because I'm eager to know that too - Edit : thanks torek! :-) )

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆