git log --before“ “没有显示提交,如果后跟一个年龄大于

问题描述 投票:1回答:1

在其他提交中,我有一个日期为2017-12-22(4b9273bda1680867)。但是当我运行git log --before '2017-12-28 00:00'时,我得到的最新结果是2017-12-19(这是599241c3003的父母之一)。

我怀疑这是由于4b9273bda1680的祖先比查询日期更新(599241c3003)但我找不到任何描述此行为的文档。

    *   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
git date
1个回答
0
投票

正如@RaymondChen和@torek提到的那样,提交有2个与之关联的日期。 “作者”日期标识您第一次运行git commit的时刻和“提交”日期时间戳提交任何重新应用(例如--amends,rebase,...)。您可以在MicrosoftDocs#git-dates上阅读更多相关信息。

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

另外根据Git log: filter by commit's author date git log不允许按作者的日期过滤(即使它是输出中的默认值)。根据作者的日期过滤的唯一方法是使用一些脚本魔术。我的bash实现:

# 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 "$@"
}

请注意,上面的示例已经在OSX上进行了测试,该OSX使用了BSD date实用程序,该实用程序与您通常在Linux系统上找到的GNU date不兼容。

© www.soinside.com 2019 - 2024. All rights reserved.