How to list only the names of files that changed between two commits How to list only the names of files that changed between two commits git git

How to list only the names of files that changed between two commits


git diff --name-only SHA1 SHA2

where you only need to include enough of the SHA hash to identify the commits. You can also do, for example

git diff --name-only HEAD~10 HEAD~5

to see the differences between the tenth latest commit and the fifth latest (or so).


git diff --name-status [SHA1 [SHA2]]

is like --name-only, except you get a simple prefix telling you what happened to the file (modified, deleted, added...)

git log --name-status --oneline [SHA1..SHA2]

is similar, but commits are listed after the commit message, so you can see when a file was changed.

  • if you're interested in just what happened to certain files/folders you can append -- <filename> [<filename>...] to the git log version.

  • if you want to see what happened for a single commit, call it SHA1, then do
    git log --name-status --oneline [SHA1^..SHA1]

File status flags:

FlagNameMeaning
MmodifiedFile has been modified
Ccopy-editFile has been copied and modified
Rrename-editFile has been renamed and modified
AaddedFile has been added
DdeletedFile has been deleted
UunmergedFile has conflicts after a merge


It seems that no one has mentioned the switch --stat:

$ git diff --stat HEAD~5 HEAD .../java/org/apache/calcite/rex/RexSimplify.java   | 50 +++++++++++++++++----- .../apache/calcite/sql/fun/SqlTrimFunction.java    |  2 +- .../apache/calcite/sql2rel/SqlToRelConverter.java  | 16 +++++++ .../org/apache/calcite/util/SaffronProperties.java | 19 ++++---- .../org/apache/calcite/test/RexProgramTest.java    | 24 +++++++++++ .../apache/calcite/test/SqlToRelConverterTest.java |  8 ++++ .../apache/calcite/test/SqlToRelConverterTest.xml  | 15 +++++++ pom.xml                                            |  2 +- .../apache/calcite/adapter/spark/SparkRules.java   |  7 +-- 9 files changed, 117 insertions(+), 26 deletions(-)

There are also --numstat

$ git diff --numstat HEAD~5 HEAD40      10      core/src/main/java/org/apache/calcite/rex/RexSimplify.java1       1       core/src/main/java/org/apache/calcite/sql/fun/SqlTrimFunction.java16      0       core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java8       11      core/src/main/java/org/apache/calcite/util/SaffronProperties.java24      0       core/src/test/java/org/apache/calcite/test/RexProgramTest.java8       0       core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java15      0       core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml1       1       pom.xml4       3       spark/src/main/java/org/apache/calcite/adapter/spark/SparkRules.java

and --shortstat

$ git diff --shortstat HEAD~5 HEAD9 files changed, 117 insertions(+), 26 deletions(-)