0
0
GitHow-ToBeginner · 3 min read

How to Use git show: View Commit Details Easily

Use git show [commit] to display details of a specific commit, including its changes, author, and message. If no commit is specified, it shows the latest commit on the current branch.
📐

Syntax

The basic syntax of git show is:

  • git show [commit]: Shows details of the specified commit.
  • commit can be a commit hash, branch name, tag, or HEAD.
  • If commit is omitted, it defaults to the latest commit on the current branch.
bash
git show [commit]
💻

Example

This example shows the details of the latest commit on the current branch, including the commit hash, author, date, commit message, and the changes made.

bash
git show
Output
commit 9fceb02d0ae598e95dc970b74767f19372d61af8 Author: Jane Doe <jane@example.com> Date: Tue Apr 27 14:00:00 2024 +0000 Fix typo in README diff --git a/README.md b/README.md index e69de29..b7a3f1a 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -Hello World +Hello World! +Added exclamation mark
⚠️

Common Pitfalls

Common mistakes when using git show include:

  • Not specifying a commit and expecting to see older commits.
  • Using incomplete or wrong commit hashes.
  • Confusing git show with git log, which shows a list of commits.

Always use a full or unique commit hash or a valid reference to avoid errors.

bash
git show 1234
# Wrong: incomplete hash may cause error or unexpected output

git show 9fceb02d0ae598e95dc970b74767f19372d61af8
# Correct: full commit hash shows exact commit details
📊

Quick Reference

CommandDescription
git showShow details of the latest commit
git show HEAD~1Show details of the commit before the latest
git show Show details of a specific commit
git show Show latest commit on a branch
git show Show commit details for a tag

Key Takeaways

Use git show to see detailed info about a specific commit.
If no commit is given, git show shows the latest commit on the current branch.
Specify full or unique commit hashes to avoid confusion or errors.
Remember git show shows one commit; use git log for multiple commits.
You can use branch names or tags as references with git show.