如何捕获 git decorate 应用的标签

How to capture the tags applied by git decorate

这是怎么回事?为什么两个输出不同?

$ git log --oneline -n1
7dbee6d (HEAD -> master, origin/master, origin/HEAD) some commit msg

$ git log --oneline -n1 | head
7dbee6d some commit msg

通往 'head' 的管道是我能找到的最简单的例子来说明问题。这个问题阻止了我,例如:

系统:

来自 log 联机帮助页:

--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 default option is short.

因此,当使用 --decorate=auto 调用时,行为将根据 stdout 是否为终端而改变。如果你将 git log 输出到某处,stdout 将不是终端。

默认值为 short,但您的 git 选项中可能有 auto

要在两种情况下获得相同的行为,请使用 --decorate=short

调用它