Search code examples
gitgit-loggit-stash

Why does --date= affect the %gd git log format?


$ git stash list --format="%gd, %cd"
stash@{0}, Fri Sep 22 11:40:25 2017 +0100
stash@{1}, Mon Sep 18 16:12:11 2017 +0100

Stash id's and long format dates. If I try to get short dates:

$ git stash list --format="%gd, %cd" --date=short
stash@{2017-09-22}, 2017-09-22
stash@{2017-09-18}, 2017-09-18

Why did the stash id also change into a date? %cd is documented to respect --date=, but not %gd (and it's not supposed to show a date anyway).


Solution

  • %gD: reflog selector, e.g., refs/stash@{1} or refs/stash@{2 minutes ago}; the format follows the rules described for the -g option. The portion before the @ is the refname as given on the command line (so git log -g refs/heads/master would yield refs/heads/master@{0}).

    %gd: shortened reflog selector; same as %gD, but the refname portion is shortened for human readability (so refs/heads/master becomes just master).

    So %gd is same as %gD and %gD's format follows the rules of -g. Let's take a look at -g.

    -g

    --walk-reflogs

    Instead of walking the commit ancestry chain, walk reflog entries from the most recent one to older ones. When this option is used you cannot specify commits to exclude (that is, ^commit, commit1..commit2, and commit1...commit2 notations cannot be used).

    With --pretty format other than oneline (for obvious reasons), this causes the output to have two extra lines of information taken from the reflog. The reflog designator in the output may be shown as ref@{Nth} (where Nth is the reverse-chronological index in the reflog) or as ref@{timestamp} (with the timestamp for that entry), depending on a few rules:

    If the starting point is specified as ref@{Nth}, show the index format.

    If the starting point was specified as ref@{now}, show the timestamp format.

    If neither was used, but --date was given on the command line, show the timestamp in the format requested by --date.

    Otherwise, show the index format.

    So it makes sense.