Are git tags just tags?

I noticed the ability of git to check for a specific commit. After that, I began to understand how git really works.

But I want to be sure that this is correct: When I create a branch, it is nothing but a tag indicating the current commit. When I check this thread, I check the commit that this "tag" points to. Now that I’ve done something, a new commit is created. The current branch verification tag is now updated, so it points to a new commit.

So ... in fact, I could do it all manually, right? This is just an opportunity to make your life easier.

+8
git
source share
3 answers

Yes, this is a good model for which industry. Beware, however, about the terminology - git also has the concept of tags, but the tags do not move - they always point to the same message.


Update: adding a bit more detailed information that might be of interest ...

The current branch is stored in a HEAD file that points to the branch, in which case the contents are as follows:

 ref: refs/heads/master 

... or it points directly to a commit, in which case the content will look like this:

 2b45553eec2019594724dcbb4c252a74cbb5f38e 

In the first case, the master branch advances when creating a new commit, but in the latter case (known as "detached HEAD", hopefully obvious reasons), no branch will be changed when creating a new commit.

+7
source share

Branch is a reference pointer; it points to the current commit, as you say.

But you should not use these words interchangeably, because they mean something else.

+4
source share

Yes, for git, the branch is basically a commit reference, which is automatically updated upon commit. You could track it yourself, as you noted.

In fact, git exposes all the low-level blocks on which the higher-level abstractions are built. If you want to use a command like git hash-object , git mk-tree and git commit-tree to manually execute git add and git commit if you want (see Raw Git in the git book for details on how to do this) .

Also note that git has two types of tag. Light tags are just a reference to a commit (via a hash) that don't move automatically. There is also the concept of tag objects, which are real git objects, archived as commit, and which can contain a message and a signature.

+3
source share

All Articles