When I do a git log –oneline command with no piping or file redirection, it gives information about the HEAD location and the branch (master in the example below)
$ git log --oneline --color=never 8bc8511 (HEAD -> day_20190316) Today # 12 1381438 Today # 11 d87d53a Today # 10 718aef9 Today # 9 b05e17e Today # 8 .... 2643d93 (master) Initial commit
However when I pipe this through less, or redirect it into a file, the HEAD and master information go away. I’ve tried redirecting stderr to join stdout, but this makes no difference.
$ git log –oneline –color=never 2>&1 | /usr/bin/more
8bc8511 Today # 12 1381438 Today # 11 d87d53a Today # 10 718aef9 Today # 9 b05e17e Today # 8 ..... 2643d93 Initial commit
I’d like to access that information, but how?
git log --oneline --decorate --color=never | less
From the git docs
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 option –decorate is short-hand for –decorate=short. Default to configuration value of log.decorate if configured, otherwise, auto.
the default when
--decorate is not specified is auto, meaning "add HEAD info if going to terminal, otherwise don’t". When you specify
--decorate without an argument, it defaults to
short, which is the short HEAD info you referenced in the question.
Answered By – jeremysprofile