Test Unsigned Commits
In this step, we will create another commit without a signature and observe how Git handles it when we use the verification commands we learned in the previous steps. This will reinforce your understanding of how Git identifies unsigned commits.
First, make sure you are in your project directory:
cd ~/project/my-time-machine
Let's add another line to our message.txt
file:
echo "This is a second message." >> message.txt
The >>
operator appends the text to the existing file. Now, let's check the status:
git status
You should see that message.txt
has been modified:
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: message.txt
no changes added to commit (use "git add" and/or "git commit -a")
Now, let's stage the changes and create a new commit. We will not sign this commit.
git add message.txt
git commit -m "Add a second message"
You will see output confirming the new commit:
[master a1b2c3d] Add a second message
1 file changed, 1 insertion(+)
Now that we have a second, unsigned commit, let's use git log --show-signature
again to see the history:
git log --show-signature
You will see both commits in the log. Neither will show signature information because we haven't configured signing yet.
commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9 (HEAD -> master)
Author: Jane Doe <[email protected]>
Date: Mon Aug 7 10:00:00 2023 +0000
Add a second message
commit u1v2w3x4y5z6a7b8c9d0e1f2g3h4i5j6k7l8m9n0
Author: Jane Doe <[email protected]>
Date: Mon Aug 7 10:00:00 2023 +0000
Send a message to the future
Finally, let's use git verify-commit
on the new commit. Get the short hash of the latest commit using git log --oneline
and replace YOUR_NEW_COMMIT_HASH
below:
git log --oneline
a1b2c3d (HEAD -> master) Add a second message
u1v2w3x Send a message to the future
Now verify the new commit:
git verify-commit YOUR_NEW_COMMIT_HASH
Again, the output will show the commit details but no signature verification status, confirming that this commit is also unsigned.
This step demonstrates that by default, Git commits are not signed. To add a layer of security and trust, you need to explicitly configure Git to sign your commits, which is a more advanced topic we won't cover in this introductory lab. However, understanding how to identify unsigned commits using git log --show-signature
and git verify-commit
is the first step in working with signed commits.