5

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?

Julio Vedovatto
  • 178
  • 1
  • 5
  • 13
  • possible duplicate of [Git: how to diff the same file between two different commits on the same branch?](http://stackoverflow.com/questions/3338126/git-how-to-diff-the-same-file-between-two-different-commits-on-the-same-branch) – Dan Moulding Jul 30 '10 at 15:07

2 Answers2

11

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

Marco Ceppi
  • 7,163
  • 5
  • 31
  • 43
3

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>
OderWat
  • 5,379
  • 3
  • 29
  • 31