Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff on date?

Tags:

git

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

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

like image 874
ylluminate Avatar asked Mar 11 '12 19:03

ylluminate


People also ask

How do I see git diff?

You can run the below commands to compare the changes for specific file: git diff HEAD <file_name> git diff <file_name>

What is git diff command?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

How do you diff commits in git?

You can compare files between two Git commits by specifying the name of the ref that refers to the commits you want to compare. A ref may be a commit ID or HEAD, which refers to the current branch. Let's compare two commits in our Git repository. The above command will perform a diff operation across our two commits.

What does M mean in git diff?

^M represents carriage return. This diff means something removed a Unicode BOM from the beginning of the line and added a CR at the end.


2 Answers

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.

like image 135
Borealid Avatar answered Oct 19 '22 15:10

Borealid


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
like image 23
Sanghyun Lee Avatar answered Oct 19 '22 14:10

Sanghyun Lee