I have got a error message while creating tag containing [
character:
fatal: '[' is not a valid tag name.
Question: are there any rules for tags in the git?
Join Stack Overflow to learn, share knowledge, and build your career.
You can check if the name is valid with
git check-ref-format
This page contains the constraints on a valid name. Quoted from the page (possibly outdated in the future):
They can include slash
/
for hierarchical (directory) grouping, but no slash-separated component can begin with a dot.
or end with the sequence.lock
.They must contain at least one
/
. This enforces the presence of a category likeheads/
,tags/
etc. but the actual names are not restricted. If the--allow-onelevel
option is used, this rule is waived.They cannot have two consecutive dots
..
anywhere.They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177
DEL
), space, tilde~
, caret^
, or colon:
anywhere.They cannot have question-mark
?
, asterisk*
, or open bracket[
anywhere. See the--refspec-pattern
option below for an exception to this rule.They cannot begin or end with a slash
/
or contain multiple consecutive slashes (see the--normalize
option below for an exception to this rule)They cannot end with a dot
.
.They cannot contain a sequence
@{
.They cannot be the single character
@
.They cannot contain a
\
.
As you can see, in your case you violated rule (5).
You can use the --normalize
flag to normalize tags with respect to slashes (removing leading slashes as well as consecutive ones):
git check-ref-format --normalize "tags/weird//tag"
The tags/
part species that you are validating a tag
.
After some discussion with @NikosAlexandris, you can write the following one liner to check the tag <some-tag>
with textual feedback:
git check-ref-format "tags/<some-tag>" && echo "Valid tag" || echo "Invalid tag"
remote/branch
, or HEAD^1
(to get the one but last commit of the head), etc. After all, a tag is just a "special name" for a commit. So in order to make the reference unabiguous between a tag, remote branch, relative path, etc. the names are restricted. On Windows, you can for example not name a file ..
, since then the path ../foo
would have some serious problems. Unix typically solves this with escaping, but here the "tag space", "branch space", "relative commit space" are "merged".
– Willem Van Onsem
Apr 22 '19 at 18:16
v1.4
is a valid tag, accepted by version 2.21.0. See Git Basics - Tagging.
– Arthur
May 27 '20 at 15:26
refs/tags/v1.4
, note that git prepends it with refs/tags/
.
– Willem Van Onsem
May 27 '20 at 15:29