git diff 日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9658110/
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-19 06:35:37  来源:igfitidea点击:

git diff on date?

git

提问by ylluminate

I'm accustomed to running a git comparison that will allow comparison with local git revs like:

我习惯于运行 git 比较,这将允许与本地 git revs 进行比较,例如:

git diff HEAD HEAD~110 -- some/file/path/file.ext

Is it possible to use the date instead? And if so, how? I would like to be able insert in place of the "110" in the above example, a date such as "4 Dec 2012".

是否可以使用日期代替?如果是这样,如何?我希望能够在上面的例子中插入一个日期来代替“110”,比如“2012 年 12 月 4 日”。

回答by Borealid

git diff HEAD 'HEAD@{3 weeks ago}' -- some/file/path/file.ext

This is not, strictly speaking, the revision made three weeks ago. Instead, it's the position HEADwas at three weeks prior to the present. But it's probably close enough for your purposes - it will be very accurate if the current branch's HEADmoved forward steadily, as most tend to do. You can improve the accuracy by using a branch name instead of HEAD.

严格来说,这不是三周前的修改。相反,它的位置HEAD是在现在之前的三周。但是对于您的目的来说它可能已经足够接近了 - 如果当前分支HEAD像大多数人那样稳定地向前移动,它将非常准确。您可以通过使用分支名称而不是HEAD.

Instead of an offset-from-the-present, you can also use a date/time, like HEAD@{1979-02-26 18:30:00}. See git help rev-parse.

您还可以使用日期/时间,例如HEAD@{1979-02-26 18:30:00}. 见git help rev-parse

回答by Sanghyun Lee

What you want must be this.

你要的一定是这个。

git diff HEAD '@{3 weeks ago}' -- some/file/path/file.ext

You should compare with @{3 weeks ago}, not HEAD@{3 weeks ago}.

你应该比较@{3 weeks ago},而不是HEAD@{3 weeks ago}

What is difference?

什么是区别?

If you were on another branch 3 weeks ago, HEAD@{3 weeks ago}would point the HEAD of the branch, on the other hand @{3 weeks ago}would point the HEAD of the current branch.

如果您在 3 周前在另一个分支上,HEAD@{3 weeks ago}将指向该分支的 HEAD,另一方面@{3 weeks ago}将指向当前分支的 HEAD。

You can also explicitly name the branch.

您还可以明确命名分支。

git diff HEAD 'master@{3 weeks ago}' -- some/file/path/file.ext

回答by Gilles 'SO- stop being evil'

Combining Jonathan Stray's suggestion to use git-rev-list --beforeto find the revision at a given date and Show just the current branch in Git:

结合Jonathan Stray 的建议,用于git-rev-list --before在给定日期查找修订并在 Git 中仅显示当前分支

#!/bin/sh
if [ $# -eq 0 ] || [ "" = "--help" ]; then
  cat <<EOF
Usage: 
git-diff-since yesterday
git-diff-since '4 Dec 2012' some/file/path/file.ext
DATE FILE... git diff on FILE... since the specified DATE on the current branch. EOF exit fi branch1=$(git rev-parse --abbrev-ref HEAD) revision1=$(git rev-list -1 --before="" "$branch1") shift revision2=HEAD git diff "$revision1" "$revision2" -- "$@"

Call this script with a date and optionally some file names, e.g.

使用日期和可选的一些文件名调用此脚本,例如

##代码##