git show <commit>:<pathname>
This command is useful for retrieving a file's historical content from a specific commit to help understand changes over time.
It works by using the object notation of <commit>:<pathname>
to extract the blob of the file from Git's internal object database, letting you inspect the file exactly as it was stored at that commit; you can substitute <commit>
with identifiers like HEAD
, branch names, or specific commit hashes, and <pathname>
with any file path within your repository.
Closely related commands include using git diff
to compare changes between commits and git log -p <pathname>
to view patch history for a file, with optional shorthand flags available such as -p
for patch format and longer flag alternatives providing similar functionality.