14

We created a tag "2012/02/16" on our git repository. We then noticed that inside of Source Tree the 2012 and 01 were represented as folders which could neatly be opened and closed to reveal and hide the tags. Having a nested hierarchy of tags seems like a nice way to organize the tags instead of just having one flat list.

Is there an issue with doing this?

When I do a git ls-remote I see the following entries:

8430572c89362b875109628c33a18e782aa38488    refs/tags/2012/02/16
d247e38159c8c4998bf8b555edfd7ffe7b945255    refs/tags/2012/02/16^{}

I'm not sure what the ^{} characters at the end of the second tag mean and I want to make sure that this behavior we stumbled upon isn't something we should not be doing before we go and leverage it to clean up our tags.

We don't see the ^{} characters on our "un-nested" tags.

1
  • 3
    ^{} is a shorthand syntax to dereference a tag recursively until it finds a non-tag object. If you're not seeing it on your other tags, that may mean your other tags are lightweight tags instead of annotated tags. Commented Feb 17, 2012 at 4:13

3 Answers 3

14

The only problem you'll encounter is an unhelpful error message if you attempt to create a tag that collides with a "directory" in your hierarchy (caused directly by the directories that git uses to store the tags colliding):

% git tag foo/bar
% git tag foo
error: there are still refs under 'refs/tags/foo'
fatal: refs/tags/foo: cannot lock the ref

This is unlikely to be a problem in practice, it normally comes up when people try and do:

v0.0.1/rc1
v0.0.1/rc2
v0.0.1/beta1
v0.0.1/beta2

then, try and tag v0.0.1, which'll hit the above problem.

1
  • Thank you so much! I had a commit tagged "1.3.39/40" and was trying to retag it as 1.3.39 and 1.3.40 seperately, so I typed git tag 1.3.39 -am "Version 1.3 Revision 39" 1.3.39/40 and got this error. Simply deleting the tag with the slash then adding the new tag by providing the commit hash solved the problem. Commented Dec 8, 2014 at 16:27
10

No problem, using a slash is standard practice for example in the "git-flow" discipline. You can check the syntax rules for tag names in the manual page git-check-ref-format (1): https://git-scm.com/docs/git-check-ref-format

The caret with brackets is something git is trying to tell you about that tag, not something you typed. You can interpret it using the manual page gitrevisions (7): https://git-scm.com/docs/gitrevisions

1
  • Note to the OP: using the slash is perfectly fine, and you can think of it as nesting, but no git commands will actually treat your set of tags as a hierarchy. That's just how they happen to be stored.
    – Cascabel
    Commented Feb 17, 2012 at 5:50
1

As well as the file/directory collision problem there's also a case-sensitivity problem you can run into. If you're running on a case-insensitive filesystem such as Windows and Mac OS X have then it's possible to have tags on a remote repository that you can't fetch/pull. For example the following would clash:

archive/some-tag-or-other
Archive/a-different-tag

as when git creates the second tag it actually gets put in the .git/refs/tags/archive directory. Once you're in that state subsequent fetches/pulls will continually try to re-get the second tag.

However there's a simple workaround for this, which is to run git pack-refs which amalgamates the individual ref files into the plain text file .git/packed-refs. Once you run that the individual tag file for the first tag will be removed along with the .git/refs/tags/archive directory, then the second tag can be successfully fetched/pulled.

1
  • 1
    Not related to the question. The tags Some-tag and some-tag will cause the same thing, without any folders involved.
    – Chronial
    Commented Jul 11, 2013 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.