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?
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.
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.
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' .
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With