Viewing a commit

We can view commits with the git show command. When doing so, we can reference a commit hash, or we can use the HEAD pointer. For example, to see the commit twice removed from the repository HEAD we run

git show HEAD~2

Git will show all the information about that commit. If instead we only want to see the final version of a file in the that commit we run

git show HEAD~2:file_path/file_name.ext

Keep in mind that if the file is not in the root of our project, we need to supply the entire path and the filename.

Viewing a commit 1
Viewing a commit 2

If we only want to see the files that were modified in a commit, we use the --name-only option

git show HEAD~2 --name-only

With this option, we can only see the names of the files. If we also want to see what was done to those files (added, delete, modified), we use the --name-status option

git show HEAD~2 --name-status