-1

I want to do a git diff, but only get a list of the files changed and lines changed per file. I have this:

git diff HEAD..origin/dev --name-only

and I get something like this:

assets/shell.sh
package.json

but I am looking for something like this:

assets/shell.sh     33 lines
package.json        5804 lines

is it possible to get such a summary?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • 2
    Like `git diff --stat`? – Ry- Oct 05 '18 at 18:41
  • 1
    Yeah like that, but against another branch..Maybe `git diff --stat origin/dev`? Can you add an answer? – Alexander Mills Oct 05 '18 at 18:53
  • I mean `git diff --stat HEAD..origin/dev` – it’s just an option. – Ry- Oct 05 '18 at 20:39
  • 1
    Possible duplicate of [Using git diff, how can I get added and modified lines numbers?](https://stackoverflow.com/questions/8259851/using-git-diff-how-can-i-get-added-and-modified-lines-numbers) – mkrieger1 Oct 05 '18 at 21:17

2 Answers2

3

You might consider using git diff --shortstat --numstat.

It shows added and deleted lines.

The output looks something like this:

$ git diff --shortstat --numstat HEAD^^..HEAD
1       1       Jenkinsfile-sciencetest
88      11      README.md
18      15      src/foo.py
1       0       src/bar.py
 4 files changed, 108 insertions(+), 27 deletions(-)

For all lines but the last one, the first column is the number of lines added. The second column is the number of lines deleted and the final column is the file name.

The last line provides the summary.

Joe Linoff
  • 761
  • 9
  • 13
0

Looks like I want to use:

git diff --stat

which will compare the worktree to the index. If I want to compared the worktree to another branch, I would use:

git diff --stat origin/dev

and to compare the index/staging area to another branch you would use:

git diff --cached --stat origin/dev
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817