In this step, we will create another commit and another tag to further practice using git rev-parse
with different tags. This will reinforce your understanding of how tags point to specific commits in your project's history.
First, ensure you are in the ~/project/my-time-machine
directory.
cd ~/project/my-time-machine
Now, let's modify the version.txt
file and create a new commit.
echo "This is the second version." >> version.txt
git add version.txt
git commit -m "Update version file to v2"
You should see output similar to this after the commit:
[master <new-commit-hash>] Update version file to v2
1 file changed, 1 insertion(+)
We've now created a new commit. Let's add another tag, v2.0
, to this latest commit.
git tag v2.0
Again, this command won't produce output, but the tag is created.
Now, let's list all the tags in our repository:
git tag
You should see both tags:
v1.0
v2.0
Finally, let's use git rev-parse
to get the commit hash for the new tag, v2.0
.
git rev-parse v2.0
This will output the full commit hash for the commit where you created the v2.0
tag:
<full-commit-hash-for-v2>
You can also use git rev-parse
to get the hash for the v1.0
tag again to see that it still points to the original commit:
git rev-parse v1.0
This will output the full commit hash for the commit where you created the v1.0
tag (the same hash you saw in Step 1):
<full-commit-hash-for-v1>
By using git rev-parse
with different tag names, you can easily retrieve the specific commit hash associated with each tagged version of your project. This is incredibly useful for navigating your project's history and referencing specific release points.