How to Show Files in Git Commit

Abdul Jabbar Feb 02, 2024
  1. Show Files in Git Commit Using the git diff-tree Command
  2. Show Files in Git Commit Using the git show Command
How to Show Files in Git Commit

When working on a team project, we must see the files committed to see the progress of the past commits. Every programmer or developer engaged with a project by committing codes regularly to a git remote repository comes across this situation.

Some need complete information about it, and some want to check the list of files with names only. There are various ways to review the files.

This article will discuss checking the list of files instead of viewing the whole information using the Git command line.

Show Files in Git Commit Using the git diff-tree Command

This command is used for comparing changes committed in Git in the past. We can take two sets of input data and get the output of those sets (the modifications done between them in the past).

It shows the changes done between the working tree and the index or two trees, two files on a disk, or two blob objects in the remote repository.

The main command to check the list of files is the git diff-tree. It is supposed to be the preferred method of listing files in a commit as it is considered a Plumbing command in Git.

When we have to compare the blobs mode or text contents, we can do it by listing files via multiple tree objects in Git.

Example command:

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

The above command results will display the names of the files pushed to the remote repository in the past.

Output:

Test.html
javascript/Vue.js
javascript/App.js

The following are the argument details used in the above sample command.

  • --no-commit-id will suppress the ID output of the commit.
  • --name-only will show only the names of the affected files. We can also use --name-status to show the status of the file, whether it is edited, modified, or deleted.
  • -r will go into sub-trees by processing one by one.

Show Files in Git Commit Using the git show Command

The following is another way of listing files, but it’s not preferable because it’s a user-friendly, Porcelain command.

Example command:

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

Again, the above command results will display the names of the files pushed to the remote repository in the past.

Output:

Test.html
javascript/Vue.js
javascript/App.js

Listed below are the details of the arguments in the sample command above.

  • --pretty describes an empty format string so that the unwanted thing at the beginning would be avoided.
  • --name-only will only display the file names. Alternatively, we can use --name-status instead to show the status of the file.
Author: Abdul Jabbar
Abdul Jabbar avatar Abdul Jabbar avatar

Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.

LinkedIn

Related Article - Git Commit