W3docs

How to List All the Files in a Git Commit

The following tutorial shows two ways of formatting files in a commit. You can find a preferred and less preferred ways with the explanation in detail.

Let's consider two ways of viewing all the changed files in a commit.

Listing files using git diff-tree command

Using <kbd class="highlighted">git diff-tree</kbd> is considered a preferred way of listing files in a commit as it is a plumbing command. It is used to compare the differences between two tree objects.

Command

listing files in a commit

git diff-tree --no-commit-id --name-only -r <sha1-commit-hash>

The result will look as follows:

index.html
javascript/application.js
javascript/ie6.js

Arguments

  • --no-commit-id - suppresses commit ID output.
  • --name-only - displays only the file names that were affected (Thanks Hank). Use --name-status argument instead to see what happened to each file (Added, Modified, Deleted).
  • -r - recurses into sub-trees.

Listing files using git show command

The following way of listing files is less preferred for scripts as it is a porcelain command:

Command

listing files in a commit git

git show --pretty="" --name-only <sha1-commit-hash>

The result will look as follows:

index.html
javascript/application.js
javascript/ie6.js

Arguments

  • --pretty - defines an empty format string to avoid the cruft at the beginning.
  • --name-only - displays only the file names that were affected (Thanks Hank). Use --name-status argument instead to see what happened to each file (Added, Modified, Deleted).

Using git diff to list all the changed files between two commits

If you want to list all changed files between two commits, use the git diff command:

list all changed files git

git diff --name-only <start-commit>..<end-commit>

You can also use <kbd class="highlighted">--name-status</kbd> to include the added, modified, or deleted change next to each file:

add change next to each file git

git diff --name-status <start-commit>..<end-commit>

Plumbing and Porcelain Commands

Since Git was initially a toolkit rather than a user-friendly Version Control System, there are a number of subcommands that do low-level work. These commands are called plumbing commands, while user-friendly commands are called porcelain.

The lower-level plumbing commands give access to the inner workings of Git, helping demonstrate the actions of Git. Many of these commands aren’t used manually on the command line but are used as building blocks for new tools and custom scripts.

The git diff Command

The git diff command is used to compare changes committed in Git. With the help of <kbd class="highlighted">git diff</kbd>, you can take two input data sets and output the modifications between them. It can display changes between the working tree and the index (or a tree), between the index and a tree, between two trees, two blob objects, or between two files on disk.