如何让 Git 日志显示今天所有的提交?

我希望能够看到我今天使用 git log所做的所有提交。我想出了 git log --after="yesterday"
然而,这对我来说似乎有点尴尬,是否有一个更简单的命令来达到同样的效果?

19608 次浏览

Maybe the best is to use

git log --since="6am"

You can adjust the time to your convenience ;)

Edit: Since this is the accepted answer I can't delete it, so I'm posting here @Simon's answer:

git log --since="6am"

And of course you can adjust the time to whatever is "morning" enough for you :)

You can create alias to shorten this command

git config --global alias.today 'log --since=7am'

and then execute:

git today

Btw, this also works:
git log --since=am

To get commits from all of today ...

git log --since=midnight

There are already several useful correct answers (e.g. git log --since="6am") but it is odd that Git's special dates are missing from the documentation (at least googling "yesterday" "noon" site:git-scm.com returns no results).

There are ways to find out what's available, for example the answers to Specification for syntax of git dates are particularly useful. In one Ryan O'Hara points out that

it seems to accept all formats that it can output, as described in the documentation for the --date option:

--date=(relative|local|default|iso|rfc|short|raw)

Only takes effect for dates shown in human-readable format, such as when using --pretty. log.date config variable sets a default value for log command’s --date option.

--date=relative shows dates relative to the current time, e.g. "2 hours ago".

--date=local shows timestamps in user’s local timezone.

--date=iso (or --date=iso8601) shows timestamps in ISO 8601 format.

--date=rfc (or --date=rfc2822) shows timestamps in RFC 2822 format, often found in E-mail messages.

--date=short shows only date but not time, in YYYY-MM-DD format.

--date=raw shows the date in the internal raw git format %s %z format.

--date=default shows timestamps in the original timezone (either committer’s or author’s).

My favourite answer there is from me_and who directs us to the git date.c class. Scan down that and you find this code (at the time of writing it is on line 925):

static const struct special {
const char *name;
void (*fn)(struct tm *, struct tm *, int *);
} special[] = {
{ "yesterday", date_yesterday },
{ "noon", date_noon },
{ "midnight", date_midnight },
{ "tea", date_tea },
{ "PM", date_pm },
{ "AM", date_am },
{ "never", date_never },
{ "now", date_now },
{ NULL }
};

I'm definitely using git log --before=tea, though looking at the date_tea function I don't think they've read Rupert Brooke:

static void date_tea(struct tm *tm, struct tm *now, int *num)
{
date_time(tm, now, 17);
}