Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git diff in same file between first and last commit

I have a text file (.yml) that I enter some texts to my system use. But now we need to know what new lines at once. I thought to use git to solve our problem, but I cant find a clarified command to do this.

Is this possible?

like image 933
Julio Vedovatto Avatar asked Jul 30 '10 00:07

Julio Vedovatto


2 Answers

You can get a list of the commits withs something like so:

git log --abbrev-commit --pretty=oneline

Which should something like this:

commitD Description
commitC Description
commitB Description
commitA Description

Choose your two commits and substitute them below:

git diff <commitA>..<commitB> -- /path/to/file

like image 82
Marco Ceppi Avatar answered Sep 26 '22 15:09

Marco Ceppi


You can do it with one commandline:

git diff -w `git rev-list HEAD --reverse | head -1`..HEAD -- <path/file>

It does not work to use --reverse with a count of 1 (-1 / --max-count 1) ... as it reverses the resulting list after truncating it. So either you use --reverse together with the head command or you use tail -1.

I had to add the -w for my usage because of switches in line-endings and tab vs. spaces usage.

This may not work as expected if the file was not added in the first commit! You may change the above line to:

git diff -w `git rev-list HEAD --reverse -- <path/file> | head -1`..HEAD -- <path/file>
like image 33
OderWat Avatar answered Sep 22 '22 15:09

OderWat