Git Show Files in a Commit
Are you adding all the correct files? Check the files that are part of a commit in git with this trick.
Once you are done with committing files in Git, you may want to list them to verify if the correct files are committed or not.
To do so, use the git show command in the following manner:
git show --name-only <commit_hash>
How to list files of a git commit
To list down the files of a git commit, you need a commit hash by which you can specify the commit to list files.
To find the commit hash, execute the git log command as shown here:
git log
Once done, you can use the commit hash in the following command to list down files of that particular commit:
git show --name-only <commit_hash>
For example, here, I wanted to list down the files of a commit that had a message saying "My second commit" so I used the following:
git show --name-only b1e9360d4496452e6b7b9bf81236e6df6bc06bac
As you can see, it shows the name of the user who performed the commit including the date and comment.
In my case, there are two files in the commit: File1.txt and File2.txt.
List files of the most recent commit
If you want to list files of the most recent commit, then you can skip the hash part from the previous command and use the HEAD
flag instead:
git show HEAD --name-only
List files of all the commits that were added or modified
If you want to list files of all the commits at once in a single repository, then you can use the git log command in the following manner:
git log --oneline --name-status
Improve your GitHub profile
But if you're a student and want to kickstart your GitHub journey, then here's how you can create a rockstar GitHub profile:
I hope you will find this guide helpful.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.