How to List Only the Names of Files That Changed between Two Commits

Better Stack Team
Updated on June 24, 2024

To list only the names of files that changed between two commits in Git, you can use the git diff command with the --name-only option. Here's how you can do it:

 
git diff --name-only <commit1> <commit2>

Replace <commit1> and <commit2> with the commit hashes, branch names, or other references for the two commits you want to compare.

For example, to list only the names of files that changed between the commits referenced by their hashes abc123 and def456, you would run:

 
git diff --name-only abc123 def456

This command will output a list of file names, each on a separate line, representing the files that changed between the two specified commits.

Note:

  • The git diff --name-only command is useful for obtaining a quick overview of the files that were modified, added, or deleted between two commits.
  • If you want to see the names of files that were modified, but not the exact changes made to them, -name-only is the appropriate option to use.
  • You can also use other options with git diff to customize the output, such as -name-status to include the type of change (modified, added, deleted) or M to detect renames.
Got an article suggestion? Let us know
Explore more
Git
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.