Lab 11: Tagging Versions in Git

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 v1.

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^

Use the git tag command again to tag this version.

git tag v0

The screenshot below shows the output of the commands used above.

Git Tag

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.

git tag

Viewing Tags in the Logs

You can also check for tags in the log.

git hist master --all

You can see both tags (v1 and v0) listed in the log output, along with the branch name master.

The screenshot below shows checking out by tag names and viewing the tags.

Git checkout by tag name and viewing tags

This content has been helpful to you?

Thanks for contributing!

Yes No