Why does a pipe remove the branch names from git log?

后端 未结 2 1202
一向
一向 2021-01-12 09:08

when I run

> git log --oneline

I get output that looks like this

abcdef0 (head, branch, origin/branch) comment
0987654 d         


        
2条回答
  •  旧巷少年郎
    2021-01-12 09:25

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

提交回复
热议问题