35

I regularly use the following command to list files changed between two commits:

git diff --name-only SHA1 SHA2

It gives a list of files somewhat like this:

/src/example/file1
/src/example/file2
/src/example/file3

There is almost no end to how useful this is.

I'd really like to be able also to show alongside each file a brief reference to the change status, indicating whether a file was added, modified or deleted.

Here's an example to demonstrate the concept:

git diff --name-only --and-how-me-the-change-status SHA1 SHA2
A /src/example/file1
M /src/example/file2
D /src/example/file3

The change status (A, M, D) is shown as an example only, I don't mind what this is so long as it is unambiguous.

I'm aware that I can use the --diff-filter option to list only added files, or only modified files or only deleted files. Using this option means I have to run three commands to get three lists of filenames. This is nice but could be nicer.

Is there a single command I can run to give me the above example output?

Jon Cram
  • 15,979
  • 22
  • 74
  • 106
  • This question is not a duplicate of http://stackoverflow.com/questions/1552340. It is very specific about asking for how to show the file status, not just a list of files. – Sean the Bean Nov 08 '16 at 17:40

1 Answers1

85

Use --name-status, it's the same as --name-only plus the status of changed files:

git diff --name-status SHA1 SHA2
Alexander Konstantinov
  • 5,266
  • 1
  • 25
  • 31