简体   繁体   中英

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?

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM