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.


  • 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
Licensed under CC-BY-NC-SA

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

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github