Julio Vedovatto
Julio Vedovatto

Reputation: 198

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?

Upvotes: 5

Views: 4395

Answers (2)

OderWat
OderWat

Reputation: 5709

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>

Upvotes: 3

Marco Ceppi
Marco Ceppi

Reputation: 7702

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

Upvotes: 11

Related Questions