Run git show with Commit Hash
In the previous steps, we learned how to create commits and view the commit log using git log
. Each commit has a unique identifier, often called a "commit hash" or "SHA". This hash is like a fingerprint for that specific save point in your project's history.
Now, let's use this commit hash to inspect a specific commit in more detail. We can use the git show
command followed by the commit hash.
First, let's get the commit hash of our first commit. Run git log
again:
cd ~/project/my-time-machine
git log --oneline
You should see output similar to this:
a1b2c3d (HEAD -> master) Send a message to the future
The short string of characters at the beginning (a1b2c3d
in this example) is the short version of the commit hash. The full hash is much longer, but Git allows you to use the short version as long as it's unique enough to identify the commit.
Copy the short commit hash from your output. Now, use the git show
command with that hash. Replace YOUR_COMMIT_HASH
with the hash you copied:
git show YOUR_COMMIT_HASH
For example, if your hash was a1b2c3d
, you would run:
git show a1b2c3d
You should see detailed information about that commit, including:
- The full commit hash
- The author and date
- The commit message
- The changes introduced in that commit (in this case, the addition of
message.txt
)
commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9 (HEAD -> master)
Author: Jane Doe <[email protected]>
Date: Mon Aug 7 10:00:00 2023 +0000
Send a message to the future
diff --git a/message.txt b/message.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/message.txt
@@ -0,0 +1 @@
+Hello, Future Me
The git show
command is incredibly useful for understanding the history of your project. You can use it to see exactly what changes were made in any given commit, which is essential for debugging or understanding how a feature was implemented.
Think of it like opening a specific time capsule from your project's history and examining its contents in detail. This ability to pinpoint and inspect past changes is a core reason why Git is so powerful for managing projects of any size.