In this article, we will see how to see the files changed in the last commit in git.
Sometimes we need to check the files that were changed in the last commit to keep track of the changes made to the repository or we may want to review the changes that we made or to ensure that the correct files were committed.
To check the files that were changed in current and last commit, we can either use the git show or git diff.
Using git show
git show command we can display the changes made in a commit. By default, it shows the changes made in the most recent commit or current commit. To display the files changed in the last commit, you can use the following command:
// Shows the files changed in current commit git show --name-only // Shows the files changed in last commit git show HEAD^ --name-only
Using git diff
git diff command we can see the difference between two commits. To view the differences between the last commit and the previous commit, you can use the following command:
git diff HEAD^ HEAD --name-only
Please note, in the above examples, HEAD^ indicates the previous commit. HEAD indicates the current or top commit and the –name-only displays only the name of the files that were changed.