So far, we've created some commits to keep track of the changes in our project. Sometimes, you might actually create a commit that takes you to an important milestone in the development cycle. For example, going from version 1 to version 2 or going from beta to alpha.
Let's make some changes to our project-1.txt file:
echo "creating a tag" >> project-1.txt
let's stage those changes:
git add .
then let's commit:
git commit -m "this is where we create a tag"
let's make sure that our commit was successful:
Now the command we will be using to tag our commit will be the
git tag command:
git tag version1
let's observe our tag in our history:
we just added the
version1 tag our latest commit.
Adding multiple tags
you can also add multiple tags to the same commit:
git tag beta git log
We now have multiple tags for the latest commit.
Assuming we accidentally added a tag, let's attempt to remove the beta tag:
git tag -d beta git log
If you look at the top right, the tag should be removed.
Adding a Tag to a previous commit
We want to add a tag to the first commit and call it version 0. we can do so with the unique SHA-1 identifier.
git tag version0 e878e0f23836e0bf0f3ca35a85758eb55672aff6
the SHA-1 identifier to my first commit is e878e0f23836e0bf0f3ca35a85758eb55672aff6, yours will be different.
Our initial commit has successfully been tagged.