Skip to content

lab 14 Tagging versions

Goals

Let’s call the current version of the hello program version 1 (v1).

Tagging version 1

Execute:

git tag v1

Now you can refer to the current version of the program as v1.

Tagging Previous Versions

Let’s tag the version immediately prior to the current version v1-beta. First we need to checkout the previous version. Rather than look 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”.

Execute:

git checkout v1^
cat hello.rb

Output:

$ git checkout v1^
Note: switching to 'v1^'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at c72af6b Rename variable to match its usage
$ cat hello.rb
names = ARGV || ["World"]

puts "Hello, #{names.join(" ")}!"
puts "You have #{names.length} names!"

See, this is the version with the default value before we added the comment. Let’s make this v1-beta.

Execute:

git tag v1-beta

Checking Out by Tag Name

Now try going back and forth between the two tagged versions.

Execute:

git checkout v1
git checkout v1-beta

Output:

$ git checkout v1
Previous HEAD position was c72af6b Rename variable to match its usage
HEAD is now at 1dee7f9 Tell user how many names they have
$ git checkout v1-beta
Previous HEAD position was 1dee7f9 Tell user how many names they have
HEAD is now at c72af6b Rename variable to match its usage

Viewing Tags using the tag command

You can see what tags are available using the git tag command.

Execute:

git tag

Output:

$ git tag
v1
v1-beta

Viewing Tags in the Logs

You can also check for tags in the log.

Execute:

git hist main --all

Output:

$ git hist main --all
* 1dee7f9 2022-10-24 | Tell user how many names they have (tag: v1, main) [Jim Weirich]
* c72af6b 2022-10-24 | Rename variable to match its usage (HEAD, tag: v1-beta) [Jim Weirich]
* 8cdd2cd 2022-10-24 | Can specify multiple names [Jim Weirich]
* 28fe396 2022-10-24 | Added a comment [Jim Weirich]
* 15c7573 2022-10-24 | Added a default value [Jim Weirich]
* 7d55044 2022-10-24 | Using ARGV [Jim Weirich]
* 91b926e 2022-10-24 | First Commit [Jim Weirich]

You can see both tags (v1 and v1-beta) listed in the log output, along with the branch name (main). Also HEAD shows you the currently checked out commit (which is v1-beta at the moment).