fghibellini
fghibellini

Reputation: 695

git log --before "<date>" not showing commit if followed by one older than <date>

Among other commits I have one dated 2017-12-22 (4b9273bda1680867). But when I run git log --before '2017-12-28 00:00' the newest result I get is dated 2017-12-19 (which is one of the parents of 599241c3003).

I suspect that this is caused by 4b9273bda1680 having an ancestor newer than the query date (599241c3003) but I cannot find any documentation describing this behaviour.

    *   commit 1a5b54d74c6130fae9806a8716744801e2152270 (HEAD -> _)
    |\  Merge: 599241c 872e57d
    | | Date:   Thu Dec 28 11:01:53 2017 +0100
    | |
    | * commit 872e57d860aa4323b394cd63cc050d4746600d93
    | | Date:   Thu Dec 28 10:58:43 2017 +0100
    | |
    | * commit 648833bd98e724e53697e2a4c2b765a1c23360ee
    | | Date:   Wed Dec 27 09:03:52 2017 +0100
    | |
    | * commit 4b9273bda16808672d6a484c5ddf7ba7e4b6a4be
    |/  Date:   Fri Dec 22 17:41:21 2017 +0100
    |
    *   commit 599241c3003e848fefc7316dbff6b64e75fbd744
    |\  Merge: 42507fd 069a9d3
    | | Date:   Thu Dec 28 11:00:45 2017 +0100

Upvotes: 1

Views: 897

Answers (1)

fghibellini
fghibellini

Reputation: 695

As @RaymondChen and @torek mentioned commits have 2 dates associated with them. The "author" date identifies the moment you ran git commit for the first time and the "commit" date timestamps any reapplication of the commit (e.g. --amends, rebase, ...). You can read more about them at MicrosoftDocs#git-dates.

Output of git log -1 --pretty=fuller 4b927:

commit 4b9273bda16808672d6a484c5ddf7ba7e4b6a4be
...
AuthorDate: Fri Dec 22 17:41:21 2017 +0100
...
CommitDate: Thu Dec 28 11:01:29 2017 +0100

Also according to Git log: filter by commit's author date git log doesn't allow to filter by the author's date (even though it's the default in the output). The only way to filter by the author's date is to use some scripting magic. My bash implementation:

# git-author-date-before()
# ------------------------
# args:
#   $1 - unix timestamp for limiting date
#   $@ - any additional arguments will be passed to `git show`.
# example usages:
#
#   git-author-date-before 1514415600
#   git-author-date-before $(date -j -f '%Y %m %d %H %M %S' '2017 12 23 00 00 00' '+%s') --pretty=fuller
#
function git-author-date-before() {
  END_TIMESTAMP="$1"; shift;
  git log --format="%at %H" \
  | sort -r \
  | awk -v t1=$END_TIMESTAMP '$1 <= t1 { print; }' \
  | cut -d ' ' -f 2 \
  | xargs git show "$@"
}

Beware that the above example has been tested on OSX which uses the BSD date utility which is incompatible with the GNU date that you usually find on a linux system.

Upvotes: 1

Related Questions