代码之家  ›  专栏  ›  技术社区  ›  user3729611

如何捕获git应用的标签

  •  2
  • user3729611  · 技术社区  · 7 年前

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

    管道到“头”是我能找到的最简单的例子来说明这个问题。这个问题使我无法解决,例如:

    • 管道到“grep”,例如某些标签到grep

    • Ubuntu 18.04.1 LTS版
    • GNU bash,版本4.4.19(1)-发行版(x86\u 64-pc-linux-GNU)
    1 回复  |  直到 7 年前
        1
  •  1
  •   OhleC    7 年前

    从 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 git log 输出到某处, stdout 不会是终点站。

    默认值为 short auto 在你的git选项中的某个地方。

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