Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: Is there something like per-branch tags?

I have some history rewriting to do for which I'd like to keep my original tree intact for now. The rewritten tree should however copy the tags previously used as well. Is there any less manual option than e.g. prepending tag names with the branch name?

like image 766
Tobias Kienzler Avatar asked Apr 18 '11 12:04

Tobias Kienzler


People also ask

Are git tags specific to a branch?

It is important to understand that tags have no direct relationship with branches - they only ever identify a commit. That commit can be pointed to from any number of branches - i.e., it can be part of the history of any number of branches - including none.

Can a git branch have multiple tags?

Git allows the creation of multiple tags on a branch or different branches. There exist two different types of git tags which are lightweight tags and the annotated git tags.

Are git tags unique?

Tags are completely separate from branches, so how you choose to handle tags doesn't depend on how you choose to handle branches. You can apply a tag to branch E' and safely delete test_branch , without losing the code in E' .

Is tag same like branch in git?

The difference between tags and branches are that a branch always points to the top of a development line and will change when a new commit is pushed whereas a tag will not change. Thus tags are more useful to "tag" a specific version and the tag will then always stay on that version and usually not be changed.


1 Answers

No, there is nothing like a per-branch tag in git. All branches and tags are just kinds of refs in Git; a ref is just a name that points to a particular revision in the revision history. For instance, if you have devel and master branches, and v1.0 and v2.0 tags, the references would look something like this:

refs/heads/devel ->  *
                    / \
                   *   * <- refs/heads/master
                   |   |
                   *   *
                    \ /
                     * <- refs/tags/v2.0
                     |
                     *
                     |
                     * <- refs/tags/v1.0
                     |
                     *

As you can see, there's nothing tying those tags to any branches; in fact, all of those tags are contained in both the master and devel branches. By looking inside your .git repo, you can see that there is really no more structure to a tag than that; it is just a file containing a SHA-1 referencing a commit within .git/refs, or a line in .git/packed-refs (tags will frequently be in packed-refs because they don't change often, while branches will usually be separate files within git/refs).

So if you want to rewrite history, and preserve the old tags, you will have to rewrite your tag names. As sehe points out, this is done using git filter-branch --tag-name-filter.

like image 102
Brian Campbell Avatar answered Oct 07 '22 13:10

Brian Campbell