- To learn how to tag commits for future references
Let’s call the current version of the hello program version 1 (v1).
01 Creating a tag of the first
git tag v1
Now, the current version of the page is referred to as v1.
02 Tags for previous versions
Let’s tag the version prior to the current version with the name v1-beta. First of all we will checkout the previous version. Instead of looking up the hash, we are going to use the
^ notation indicating “the parent of v1”.
v1^ notation causes troubles, try using
v1~1, referencing the same version. This notation means “the first version prior to v1”.
git checkout v1^ cat hello.html
$ git checkout v1^ Note: checking out '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 performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 8c32287... Added standard HTML page tags $ cat hello.html <html> <body> <h1>Hello, World!</h1> </body> </html>
This is the version with
<body> tags, but without
<head>. Let’s make it’s the v1-beta version.
git tag v1-beta
03 Check out by the tag name
Now try to checkout between the two tagged versions.
git checkout v1 git checkout v1-beta
$ git checkout v1 Previous HEAD position was 8c32287... Added standard HTML page tags HEAD is now at fa3c141... Added HTML header $ git checkout v1-beta Previous HEAD position was fa3c141... Added HTML header HEAD is now at 8c32287... Added standard HTML page tags
04 Viewing tags with the
You can see the available tags using the
git tag command.
$ git tag v1 v1-beta
05 Viewing tags in logs
You can also check for tags in the log.
git hist master --all
$ git hist master --all * fa3c141 2011-03-09 | Added HTML header (v1, master) [Marina Pushkova] * 8c32287 2011-03-09 | Added standard HTML page tags (HEAD, v1-beta) [Marina Pushkova] * 43628f7 2011-03-09 | Added h1 tag [Marina Pushkova] * 911e8c9 2011-03-09 | First Commit [Marina Pushkova]
You can see tags (
v1-beta) listed in the log together with the name of the branch (
HEAD shows the commit you checked out (currently