In this tutorial I will show you how to tag commits with names for future reference. You may need to tag commits after a stable release of your application/project.
Tagging Current Commit
Let’s call the current version of the hello program version 1 (v1). Use the
git tag command to tag the current version of your program.
git tag v1
Now you can refer to the current version of the program as
Tagging Previous Versions
Let’s tag the version just prior to the current version as v0. First we need to checkout the previous version.
Rather than lookup up the hash, we will use the
^ notation to indicate “the parent of v1”. If the
v1^ notation gives you any trouble, you can also try
v1~1, which will reference the same version. This notation means “the first ancestor of v1”.
git checkout v1^
git tag command again to tag this version.
git tag v0
The screenshot below shows the output of the commands used above.
Checking Out by Tag Name
Now you can use the tag names to check out that commit. Try the following.
To checkout the version 1.
git checkout v1
To checkout the version just prior to version 1.
git checkout v0
Viewing Tags using the tag command
You can see what tags are available using the git tag command.
Viewing Tags in the Logs
You can also check for tags in the log.
git hist master --all
You can see both tags (
v0) listed in the log output, along with the branch name
The screenshot below shows checking out by tag names and viewing the tags.
This content has been helpful to you?
Thanks for contributing!