我相信一般的解决方案是使用:
git rev-list -n1 --first-parent --until=
如果没有--first-parent,您可能会从一个分支中获得一个提交,该分支后来被合并到,a ref但截至时尚未被合并a date string。
这是使用--children和grep代替的替代方法-n1:
mlm_git_ref_as_of() {
# # Examples #
#
# Show all commits between two dates:
#
# git log $(mlm_git_ref_as_of '2012-05-21 09:00:00-0400')..$(mlm_git_ref_as_of '2012-05-21 17:00:00-0400')
#
# Show diffs of all commits between two dates:
#
# git diff $(mlm_git_ref_as_of '2012-05-21 09:00:00-0400')..$(mlm_git_ref_as_of '2012-05-21 17:00:00-0400')
local as_of="$1"
local ref="${2:-HEAD}"
# Get the most recent commit (--children, grep -v ' ') that was on
# the given branch ($ref, --first-parent) as of a given date
# ($as_of)
git rev-list --children --first-parent --until="$as_of" "$ref" | grep -v ' '
}
git whatchanged在阅读此问答之前,我并不熟悉,但是它给我带来了截然不同的结果,因此我不确定它在做什么。