Git List Files in Commit

Git has come up with many commands to perform different functionalities. One of the most important commands is the “git commit” instruction. The git commit statement is used to take a snap of the project’s active modifications. Committed screenshots are “secure” copies of a work that Git would never modify until you tell it to.

All modifications are saved to the local folder or repository using the “commit” instruction. This implies that simply though a file has been modified, it will not be involved in the next commit. To designate the preferred modifications for insertion, use the “git add” instruction instead.

This article will demonstrate the use of some commands to display all files in a single commit. Let’s start by opening the Kali Linux already installed on your Windows 10 system via the WSL tool. The black screen of the Kali Linux distribution will be unlocked on your desktop showing the console area for the admin user i.e. “kalsoom” in our case.

Before moving further, we will make sure that our Kali Linux distribution is up to date with newer and error-free functionalities. For this, we are using the “update” instruction of its console. The “apt-get” package has been used here to execute this instruction with sudo rights.

As it is a critical process for updating, it will ask for your user account password to continue. Add your account password and hit the Enter key to update your Kali Linux distribution.

Make sure to install the latest version of “git” at your Kali Linux distribution with the “apt-get” package in the install instruction. After the git is installed, you need to create a new git repository locally.

Before that, you can clone the remote repository as well. But in our case, we have been skipping that step to avoid the complexities. The “git init” instruction has been creating a local “test” repository on our Kali Linux system as per the shown output.

Let’s move within the git repository ‘test’ via the “cd” instruction. It must be empty since we have just created it. So, we have been creating a new bash file within it utilizing the “touch” instruction on the query area along with the new file name i.e. “”. We have been opening the newly made bash file in a “nano” editor to perform some bash coding in it.

After opening it, we added bash support at its first line and added a single line code i.e. “echo” statement to display some text. Let’s save this bash file and exit with Ctrl+S and Ctrl+X.

While running the newly updated bash file with the “bash” instruction, the “echo” statement within it got executed. Thus, it is showing the text we want to display on our shell.

Let’s add another text data within the “README” file of the text repository using the “echo” statement and “>” character. The README file has been created in the “test” repository now.

After using the “cat” instruction to see the data in a “README” file, we have got the text just added in it, displayed on the shell screen.

Now, our git repository “test” has two files in it as per the list “ls” instruction.

We used the “git add” instruction to add both the files into the index of a git repository.

Before this, we hadn’t used any commit instruction. Let’s commit the overall process we have done by a “git commit” instruction followed by a “-m” option and a text display message. This commit is showing that the 2 files have been created and modified i.e. inserted data.

List Files in Commit

Now, it’s time to see all the committed files in this commit. For this, try out the “git log” instruction on your Kali Linux shell while you are in the “test” repository. It shows the first commit ID, its author name, author email, date, and time on which it has been done. The display message for this commit shows the names of the list within it.

The above illustration doesn’t display the files which are committed by a user. Thus, we need to use another command that can show the file names prominently and separately at its output. Therefore, we have been utilizing the “git log” instruction with the “—raw” option.

On execution of this query, it shows the same information as we got in the above illustration. Also, it displays both the files that are generated according to this commit separately with the IDs.

Create a new text file and add some data to it using the ‘touch’ and ‘echo’ instructions.

Add this file to the git repository “test”.

Now, use the git commit instruction to reflect the addition of one.txt file.

You can also try the “—name-only” option with the commit ID in the “git show” instruction to separately display the file name as shown below.

The git show command for the first commit displayed both file names.

The use of the “—pretty” option and “—name-only” option will not display anything other than the files used in the commit as demonstrated below.


This article has been started with the introduction of a git commit command, its usage, and its functionality in a git. We created several files in a git repository and used the git add and git commit instructions after that. Several instructions like “git show” and “git log” are used with different options i.e.”—pretty”, “—raw”, “—name-only” to show the files list used in the commit.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content