Search code examples
gitgit-log

Git Log Print Ref Metadata to File


When I run git log and view in the pager I get some nice ref metadata next to commits:

commit 212b18778130cdf36effe441890826b76b97a09f (HEAD -> master, tag: TAG_8.0.2, origin/author/bootstrap_gcm, origin/master, origin/HEAD)
Merge: 4d7e0962f 7f687a431
Author: Joe, Smith <joe.smith@company.com>
Date:   Sun Oct 4 18:03:37 2020 -0400

    Merge branch 'jsmith/8.0.0_changes' into 'master'

    See merge request project/project!1286

commit 4d7e0962fadc17ac3af23a85b64ecaf65d68bc42 (tag: TAG_8.0.1)
Merge: e7ccb690f cd10de563
Author: Joe, Smith <joe.smith@company.com>
Date:   Fri Oct 2 19:54:31 2020 -0400

    Merge branch 'project2' into 'master'

    See merge request project/project!1285

The ref metadata I am talking about is:

(HEAD -> master, tag: TAG_8.0.2, origin/author/feature_br1, origin/master, origin/HEAD)
(tag: TAG_8.0.1)

-- Off to the right of the commit in parenthesis.

However, if I do git --no-pager log > git.log, all that ref info is missing:

commit 212b18778130cdf36effe441890826b76b97a09f
Merge: 4d7e0962f 7f687a431
Author: Joe, Smith <joe.smith@company.com>
Date:   Sun Oct 4 18:03:37 2020 -0400

    Merge branch 'jsmith/8.0.0_changes' into 'master'

    See merge request project/project!1286

commit 4d7e0962fadc17ac3af23a85b64ecaf65d68bc42
Merge: e7ccb690f cd10de563
Author: Joe, Smith <joe.smith@company.com>
Date:   Fri Oct 2 19:54:31 2020 -0400

    Merge branch 'project2' into 'master'

    See merge request project/project!1285

Two questions.

  1. Why? Shouldn't the same text sent to the pager also be redirected to a file?

  2. Is there a way I can preserve the ref info in parenthesis when dumping to file?


Solution

  • Shouldn't the same text sent to the pager also be redirected to a file?

    No: the default setting for decorate is decorate=auto, and auto means:

    • on (set to short) when going to the screen (perhaps through a pager), but
    • off (set to no) when going to a file.

    That's precisely why:

    git --no-pager log --decorate > git.log
    

    works: --decorate is short for setting the decorate setting to short, for the execution of this one command.

    Note that using git config, you can configure your own personal default setting for the decorate option. See the git config documentation; search for log.decorate.