Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的git日志输出在管道中被破坏了?_Git_Shell_Pipe - Fatal编程技术网

为什么我的git日志输出在管道中被破坏了?

为什么我的git日志输出在管道中被破坏了?,git,shell,pipe,Git,Shell,Pipe,如果我让Git使用其内置的head样式的日志截断,我得到的正是我所期望的: $ git log --color=always --graph -5 * 5abf1e7b0aba45e895bbe5b235f2326ad808ad30 (HEAD -> feature/blahblah, origin/feature/blahblah

如果我让Git使用其内置的
head
样式的日志截断,我得到的正是我所期望的:

$ git log --color=always --graph -5                                                                               

* 5abf1e7b0aba45e895bbe5b235f2326ad808ad30 (HEAD -> feature/blahblah, origin/feature/blahblah) blah blah last commit message
* c7b065e3d06ed8066ded283c2feec17e9f5a95d6 whitelist the new field
* 6b4332b951b2b37dec4c0fc67defb778dbdc29d7 add blah blah model
* 323c7570388f13aad8144292ebeb31187eb1c742 add blah blah to the database
* bceae36bda53b48679556eb00ee8321f1c8392e6 (origin/feature/yadayada, feature/yadayada) add blah blah to each blah blah
但是如果我使用
head
,它会删除分支标记(我想要!)

当我将
git log
的输出传输到另一个工具时,如何避免丢失这些分支标记


(我试图通过管道将输出传输到
fzf
,为了得到我想要的东西,它需要反转,但Git不允许将
--graph
--reverse
一起使用,所以我必须使用外部实用程序(如
tac
)反转输出(实际上是macOS上的
gtac
),这会导致我丢失分支标记,这是我编写自己的函数而不是使用
fcs
示例的三个主要原因之一。)

您指的是
(HEAD->feature/foo)
装饰,它有时出现,有时不出现,以某种方式神奇地自动检测您是否通过其他程序通过管道传输了git日志

这些装饰是在各种旗帜的控制下添加的,如中所述:

--装饰[=short | full | auto | no]

    打印显示的任何提交的引用名称。如果指定了short,则不会打印ref名称前缀refs/heads/、refs/tags/和refs/remotes/。如果指定了full,将打印完整的ref名称(包括前缀)。如果指定了auto,则如果输出将发送到终端,则ref名称将显示为short,否则不显示ref名称。默认选项为短。
(这里的黑体字是我的)


较旧版本的Git没有那么花哨,一些较旧版本默认为
no
,而不是
auto
short
,但这个选项已经存在很长时间了。此外,您可以在每用户
git config--global
设置中配置自己的默认值。您可能有一个默认为
auto
(这是我的赌注)的Git版本,或者将您的设置配置为
auto

什么版本的Git和什么操作系统?我使用Git2.14.3在OSX上得到了非常不同的结果,我使用的是OSX10.11(因为Karabiner),Git2.16.1版本
$  git log --color=always --graph | head -5                                                                        

* 5abf1e7b0aba45e895bbe5b235f2326ad808ad30 blah blah last commit message
* c7b065e3d06ed8066ded283c2feec17e9f5a95d6 whitelist the new field
* 6b4332b951b2b37dec4c0fc67defb778dbdc29d7 add blah blah model
* 323c7570388f13aad8144292ebeb31187eb1c742 add blah blah to the database
* bceae36bda53b48679556eb00ee8321f1c8392e6 add blah blah to each blah blah