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".
You can run the below commands to compare the changes for specific file: git diff HEAD <file_name> git diff <file_name>
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.
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.
^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.
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With