How do you display the raw contents of a commit?
Posted by OliviaWm
Last Updated: June 28, 2024
To display the raw contents of a commit in Git, you can use the git show command followed by the commit hash (or the branch name). This command provides a detailed view of the commit, including the commit message, author information, date, and the changes made in that commit. Here is the general syntax:
git show <commit-hash>
For example, to display the raw contents of a specific commit, you would run:
git show abc1234
Replace abc1234 with the actual commit hash you want to inspect.
Additional Options
- If you want to see only the raw diff of the commit (without the commit message), you can use the --pretty option:
git show --pretty="" <commit-hash>
- To view the raw contents of specific files in a commit, you can use:
git show <commit-hash>:<path/to/file>
This will display the contents of the specified file as it was at that commit.
Example
To see a file called example.txt in commit abc1234, you would run:
git show abc1234:example.txt
This provides an easy way to preview the state of files as they were at the time of specific commits.