Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What names are valid git tags?

Tags:

git

git-tag

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?

like image 766
Aik Avatar asked Oct 15 '14 12:10

Aik


People also ask

What is tag name in git?

Tags are ref's that point to specific points in Git history. Tagging is generally used to capture a point in history that is used for a marked version release (i.e. v1. 0.1). A tag is like a branch that doesn't change. Unlike branches, tags, after being created, have no further history of commits.

What types of tags does git support?

Git supports two types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesn't change — it's just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database.

What is the validity of git tag?

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.

How will you list your tags in git?

List Local Git Tags. In order to list Git tags, you have to use the “git tag” command with no arguments. You can also execute “git tag” with the “-n” option in order to have an extensive description of your tag list. Optionally, you can choose to specify a tag pattern with the “-l” option followed by the tag pattern.

What are the different types of tags in Git?

Git supports two types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database.

What version number should I use for Git tags?

A common pattern is to use version numbers like git tag v1.4. Git supports two different types of tags, annotated and lightweight tags. The previous example created a lightweight tag.

What are the best practices for Git tagging?

Suggested best practices for git tagging is to prefer annotated tags over lightweight so you can have all the associated meta-data. Executing this command will create a new annotated tag identified with v1.4. The command will then open up the configured default text editor to prompt for further meta data input.

How to tag a specific commit in Git?

Now you can check yourself by executing git log --oneline command that the tag creation is successful. Although this command will tag the last commit on the branch dev , you can also tag with a specific commit in Git. How To Tag Specific Commit In Git? For tagging a specific commit, we will make use of the hash code of that particular commit.


1 Answers

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):

  1. They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.

  2. They must contain at least one /. This enforces the presence of a category like heads/, tags/ etc. but the actual names are not restricted. If the --allow-onelevel option is used, this rule is waived.

  3. They cannot have two consecutive dots .. anywhere.

  4. They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL), space, tilde ~, caret ^, or colon : anywhere.

  5. They cannot have question-mark ?, asterisk *, or open bracket [ anywhere. See the --refspec-pattern option below for an exception to this rule.

  6. They cannot begin or end with a slash / or contain multiple consecutive slashes (see the --normalize option below for an exception to this rule)

  7. They cannot end with a dot ..

  8. They cannot contain a sequence @{.

  9. They cannot be the single character @.

  10. 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" 
like image 69
Willem Van Onsem Avatar answered Sep 17 '22 08:09

Willem Van Onsem