git diff on date?

后端 未结 3 1565
你的背包
你的背包 2020-12-13 08:22

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

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

相关标签:
3条回答
  • 2020-12-13 08:45

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

    #!/bin/sh
    if [ $# -eq 0 ] || [ "$1" = "--help" ]; then
      cat <<EOF
    Usage: $0 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="$1" "$branch1")
    shift
    
    revision2=HEAD
    
    git diff "$revision1" "$revision2" -- "$@"
    

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

    git-diff-since yesterday
    git-diff-since '4 Dec 2012' some/file/path/file.ext
    
    0 讨论(0)
  • 2020-12-13 08:46

    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}.

    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.

    You can also explicitly name the branch.

    git diff HEAD 'master@{3 weeks ago}' -- some/file/path/file.ext
    
    0 讨论(0)
  • 2020-12-13 08:49
    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 HEAD was 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 HEAD moved forward steadily, as most tend to do. You can improve the accuracy by using a branch name instead of 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.

    0 讨论(0)
提交回复
热议问题