git diff <commit> --name-only

Show only the names of files that changed compared to a specific commit.

This command is useful when you want a quick overview of which files changed relative to a given point in history, without being distracted by the full line-by-line diffs.

This command runs a git diff between your current working tree (or HEAD if everything is committed) and the specified <commit>, but with the --name-only flag so that Git prints only the paths of changed files instead of full diffs; <commit> can be anything Git understands as a commit reference (for example abc1234, HEAD~1, main, or a tag), and --name-only is just a shorter way of writing the same flag instead of a longer form that lists only filenames. By default, it shows all files that differ between your current state and <commit>, including modified, added, and deleted files.

You can combine this with other flags to refine which files are shown, for example adding --cached (git diff <commit> --name-only --cached) to compare only what is staged, or using a path filter like git diff <commit> --name-only -- src/ to list only changed files under the src/ directory; swapping --name-only for --name-status (git diff <commit> --name-status) shows filenames plus a short status code like A, M, or D, and using a range such as git diff <old-commit> <new-commit> --name-only lists files changed between two specific commits instead of between <commit> and your current state.

Closely related commands include git show --name-only <commit>, which lists files changed in a single commit, and git diff --name-only with no <commit>, which compares your working tree to HEAD; you can also pair this with commands like xargs to run tools only on changed files, for example git diff <commit> --name-only | xargs eslint to lint only modified JavaScript files.

Examples:

  • git diff HEAD~1 --name-only
  • git diff main --name-only
  • git diff abc1234 --name-only
Manual page
git diff
Related commands

Welcome to GitExamples!

Sign in to gitexamples