git 如何查看特定日期的所有提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19987099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:18:31  来源:igfitidea点击:

How do I view all commits for a specific day?

gitgit-log

提问by 3cheesewheel

I've already looked at the relevant docs from git-scm.comand gitref.org, but I can't seem to figure this out.

我已经看过来自git-scm.comgitref.org的相关文档,但我似乎无法弄清楚这一点。

Let's say I want to get all commits for Tuesday, November 12th, 2013. Using an existing repo as an example, I know for a fact that I have commits on that day, as well as commits the day before and the day after.

假设我想获得 2013 年 11 月 12 日星期二的所有提交。以现有的 repo 为例,我知道我在当天提交的事实,以及前一天和后一天的提交。

With 2013-11-11and 2013-11-12

随着2013-11-112013-11-12

All the following give me commits for both November 11th and 12th:

以下所有内容都给了我 11 月 11 日和 12 日的承诺:

  • git log --after="2013-11-11" --until="2013-11-12"
  • git log --since="2013-11-11" --until="2013-11-12"
  • git log --after="2013-11-11" --before="2013-11-12"
  • git log --since="2013-11-11" --before="2013-11-12"
  • git log --after="2013-11-11" --until="2013-11-12"
  • git log --since="2013-11-11" --until="2013-11-12"
  • git log --after="2013-11-11" --before="2013-11-12"
  • git log --since="2013-11-11" --before="2013-11-12"

With 2013-11-12only

2013-11-12

All the following give me no commits:

以下所有内容都没有给我提交:

  • git log --since="2013-11-12" --until="2013-11-12"
  • git log --since="2013-11-12" --before="2013-11-12"
  • git log --after="2013-11-12" --until="2013-11-12"
  • git log --after="2013-11-12" --before="2013-11-12"
  • git log --since="2013-11-12" --until="2013-11-12"
  • git log --since="2013-11-12" --before="2013-11-12"
  • git log --after="2013-11-12" --until="2013-11-12"
  • git log --after="2013-11-12" --before="2013-11-12"

With 2013-11-12and 2013-11-13

随着2013-11-122013-11-13

As expected (from the results of 2013-11-11and 2013-11-12above), all of the following give me results from both November 12th and 13th:

正如预期的那样(根据2013-11-112013-11-12以上的结果),以下所有内容都给了我 11 月 12 日和 13 日的结果:

  • git log --since="2013-11-12" --before="2013-11-13"
  • git log --after="2013-11-12" --before="2013-11-13"
  • git log --since="2013-11-12" --until="2013-11-13"
  • git log --after="2013-11-12" --before="2013-11-13"
  • git log --since="2013-11-12" --before="2013-11-13"
  • git log --after="2013-11-12" --before="2013-11-13"
  • git log --since="2013-11-12" --until="2013-11-13"
  • git log --after="2013-11-12" --before="2013-11-13"

...and so on and so forth. I feel like I've tried every possible combination of since, after, before, and untilbut still can't find the answer, nor do I understand whether those options are inclusive or exclusive, since they seem to be inclusive if the two dates are different, but exclusive if they're on the same day. Did I miss something / what am I doing wrong?!

...等等等等。我觉得我已经尝试了since, after, before, 的所有可能组合,until但仍然找不到答案,我也不明白这些选项是包容性的还是排斥性的,因为如果两个日期不同,它们似乎是包容性的,但是如果他们在同一天,则独家。我错过了什么/我做错了什么?!

回答by 3cheesewheel

Thanks John Bartholomew!

谢谢约翰巴塞洛缪!

The answer is to specify the time, e.g. git log --after="2013-11-12 00:00" --before="2013-11-12 23:59"

答案是指定时间,例如 git log --after="2013-11-12 00:00" --before="2013-11-12 23:59"

回答by Kohányi Róbert

I usually check my git log and see what I was working on a specific day and update my timesheet based on that, but it's a pain in the ass to type in the full date in ISO format so I just do it like this

我通常检查我的 git 日志并查看我在特定日期工作并基于此更新我的时间表,但是以 ISO 格式输入完整日期很麻烦,所以我只是这样做

git log --after=jun9 --before=jun10

and I add --authorto only print my commits

我添加--author只打印我的提交

git log --since=jun9 --until=jun10 --author=Robert 

This prints commits that happened on the last 9th of June (so for 2016 in this case and not for 2015 or 2014 and so on).

这会打印在 6 月最后 9 日发生的提交(因此在这种情况下是 2016 年,而不是 2015 年或 2014 年等)。

The --since/--afterand --until/--beforeparameters can also take stuff like 3 days ago, yesterday, etc.

--since/--after--until/--before参数也可以采取这样的东西3 days agoyesterday等等。

回答by Wallace Sidhrée

Nothing wrong with the accepted answer (which I upvoted), but... we're here for science!

接受的答案没有错(我赞成),但是......我们是为科学而来的!

The output below can be expanded/customised with pretty=format:<string>placeholders:

可以使用pretty=format:<string>占位符扩展/自定义以下输出:

git log --pretty='format:%H %an %ae %ai' | grep 2013-11-12

Not 100% immune to errors as the same string could have been entered by a user.But acceptable depending on which placeholders are used. The snippet above would not fail, for instance.

不能 100% 避免错误,因为用户可能输入了相同的字符串。但可以接受,具体取决于使用的占位符。例如,上面的代码片段不会失败。

One could as well just parse the whole git logto JSONand consume/manipulate its data to one's heart content. Check https://github.com/dreamyguy/gitloggout and never look back!

人们也可以将整体解析git logJSON并消费/操纵其数据以达到自己的核心内容。检查https://github.com/dreamyguy/gitlogg,永远不要回头!

Disclaimer:that's one of my projects.

免责声明:这是我的项目之一。

回答by Michael Gro?e

I made an alias for that specific purpose:

我为该特定目的创建了一个别名:

commitsAtDate = "!f() { git log --pretty='format:%C(yellow)%h %G? %ad%Cred%d %Creset%s%C(cyan) [%cn]' --decorate --after=\" 0:00\" --before=\" 23:59\" --author \"`git config user.name`\"; }; f"

Usage:

用法:

git commitsAtDate 2017-08-18

回答by Mike Slinn

This script displays the available date range of commits for the current repo, then prompts for the date that you want to see commits from. It displays a short SHA and the full SHA, the author, the commit timestamp, and the comments in single quotes.

此脚本显示当前存储库的可用提交日期范围,然后提示您希望查看提交的日期。它显示短 SHA 和完整 SHA、作者、提交时间戳和单引号中的注释。

The script keeps prompting for dates until you press Enter or Control-D.

该脚本一直提示输入日期,直到您按 Enter 或 Control-D。

Mac users: requires gnu date.

Mac 用户:需要 gnu 日期。

#!/bin/bash

COMMITS=`git log --abbrev-commit --pretty="format:%h %H %ai" | sort -k3 -k4`
FIRST=`echo "$COMMITS" | head -n 1`
LAST=`echo "$COMMITS" | tail -n 1`
echo "First commit: $FIRST"
echo "Last commit: $LAST"
printf "Date to search for commits: "
read DATE
while [[ "$DATE" ]]; do
  NEXT_DATE=`date +%Y-%m-%d -d "$DATE +1 day"`
  #echo "Searching for commits from $DATE to $NEXT_DATE"
  echo `git log --after="$DATE" --before="$NEXT_DATE" --pretty="format:%h %H %an %ci '%s'"`
  printf "\nDate to search for commits: "
  read DATE
done

I called the script commitsOnDates, and here it is in action. The first date I enter has no commits, so the response is just an empty line:

我调用了 script commitsOnDates,现在它正在运行。我输入的第一个日期没有提交,所以响应只是一个空行:

$ commitsOnDates
First commit: 375bcfb 375bcfbbf548134a4e34c36e3f28d87c53b2445f 2015-08-03 13:37:16 -0700
Last commit: 1d4c88c 1d4c88ce6a15efaceda1d653eed3346fcae8f5e6 2018-10-13 21:32:27 -0700
Date to search for commits: 2015-08-13


Date to search for commits: 2015-08-03
375bcfb 375bcfbbf548134a4e34c36e3f28d87c53b2445f Mike Slinn 2015-08-03 13:37:16 -0700 'this is a comment'

Date to search for commits: 2018-10-13
1d4c88c 1d4c88ce6a15efaceda1d653eed3346fcae8f5e6 Mike Slinn 2018-10-13 21:32:27 -0700 'a comment' 64d6e16 64d6e16338657b82c91ac94bea8ebf7b80dc4c28 Mike Slinn 2018-10-13 18:28:41 -0700 'nother comment' d5eb26e d5eb26e49fc9dceee9b9f5a2d8fa052bff2cfbbc Mike Slinn 2018-10-13 18:16:20 -0700 'no comment' d8a4992 d8a4992df208ba5efb50728311820bdad5ba5332 Mike Slinn 2018-10-13 12:02:00 -0700 'commented'

Date to search for commits: