How to List All the Files in a Git Commit

  1. Listing files using git diff-tree command
    1. Command
    2. Arguments
  2. Listing files using git show command
    1. Command
    2. Arguments
  3. Using git diff to list all the changed files between two commits
  4. Plumbing and Porcelain Commands
  5. The git diff Command

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

Listing files using git diff-tree command

Using git diff-tree is considered as a preferred way of listing files in a commit as it is a plumbing command. It is used to compare the content and mode of blobs found via two tree objects.

Command

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 ID output of the commit.
  • --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

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 for avoiding 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:

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

You can also use --name-status to include the added, modified or deleted change next to each file:

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 is used to compare changes committed in Git. With the help of git diff, 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.


Do you find this helpful?

Related articles