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

查看:71
本文介绍了为什么管道从git日志中删除分支名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我跑步时

 > git log --oneline 

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

  abcdef0(头,分支,源/分支)注释
0987654不同的注释
1234567(不同的分支,源/分支)第三注释

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

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

这意味着我无法grep或添加行号,或类似的东西。



(它也缺少颜色和 less 样式行为,但我没有



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

解决方案

一开始,我也注意到在进行bash打击之后缺少颜色,但是您对装饰的描述(分支和t ag名称)消失是奇怪的。让我们分别处理它们。



自行解决分支名称(装饰)

 -装饰

是这样做的标志镜头使用。



要获得永久效果,可以在



关于颜色



不,我不知道在传递给bash时如何/为什么会断裂,我将让更多的高级用户回答部分。 (就像我说的那样,很高兴您问了这个问题,因为我也很想知道这个问题-编辑:谢谢torek!:-)


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! :-) )

这篇关于为什么管道从git日志中删除分支名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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