Tags

tags

Another interesting concept in git are commit pointers,
in git these are called tags

A tag identifies a specific commit with a meaningful name, replacing the complicated hash

tags

What are they for?

Tags are used to identify a commit as a significant one

e.g. tags could be used to identify the commit of a specific release of a program

tags

How can we create a tag?

git tag <tag_name> [<commit_hash>]

The command tag requires a name for the tag and optionally the hash of the commit which has to be tagged (If no hash is provided the "last" commit will be tagged)

n.b. tag name must be short and simple,
for more complex notes you can also add a message with the argument -m, followed by the message
tags

Tag a specific commit

git tag v1.2.0 be4f621
tag

A pointer is added to the commit with the specified name

tags

How can we get the list of tags?

Simply using

git tag
v1.0
v1.1.1
v1.2.0
(END)

tag without parameters returns the list of the repository tags

tags

History as commit pointers

As we said earlier each commit has a pointer to its parent, so we can see the entire history of a git repo like a collection of commits and commit pointers

history with pointers
tags

Branches as commit pointers

We used an intuitive meaning of branch for simplicity, but in the real git the branches are really similar to commit pointers

In particular branch is a pointer to the last commit of the "intuitive branch"

branches like tags

Branches are tags
(more or less)

tags

Which commit is a new one attached to?

The answer is "the commit pointed to by HEAD"

tags

The special tag HEAD

HEAD is a special tag pointing the current working branch
in an ordinary situation

HEAD tag
tags

Which operations (implicitly) move HEAD?

tags

What if we want to move HEAD
to a specific commit?

To do this we can use the command checkout with the hash of the commit we want move HEAD to

git checkout <commit_hash>
detached HEAD n.b. when HEAD points to a specific commit not pointed to by a branch, we call it detached HEAD