git 在 GitHub 存储库中创建标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18216991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:46:02  来源:igfitidea点击:

Create a tag in a GitHub repository

gitgithubgit-tag

提问by Tanel Tammik

I have a repository in GitHub and I need to tagit.
I tagged in a shell, but on GitHub, it is not showing up.

我在 GitHub 中有一个存储库,我需要标记它。
我在 shell 中进行了标记,但在GitHub 上,它没有出现。

Do I have to do anything else?

我还需要做什么吗?

The command I used in the shell is:

我在shell中使用的命令是:

git tag 2.0

And now when I type git tagit shows:

现在当我输入git tag它时显示:

2.0

So it seems like tags are present, correct?

所以看起来标签存在,对吗?

The repository is: https://github.com/keevitaja/myseo-pyrocms.

存储库是:https: //github.com/keevitaja/myseo-pyrocms

How do I make this tag show up on GitHub? Where are my tags?

如何让这个标签显示在 GitHub 上?我的标签在哪里?

回答by

You can create tags for GitHub by either using:

您可以使用以下任一方法为 GitHub 创建标签:

  • the Git command line, or
  • GitHub's web interface.
  • Git 命令行,或
  • GitHub 的网页界面。

Creating tags from the command line

从命令行创建标签

To create a tag on your current branch, run this:

要在当前分支上创建标签,请运行以下命令:

git tag <tagname>

If you want to include a description with your tag, add -ato create an annotated tag:

如果要在标签中包含描述,请添加-a以创建带注释的标签

git tag <tagname> -a

This will create a localtag with the current state of the branch you are on. When pushing to your remote repo, tags are NOT included by default. You will need to explicitly say that you want to push your tags to your remote repo:

这将创建一个local带有您所在分支的当前状态的标签。推送到远程仓库时,默认情况下不包含标签。您需要明确说明要将标签推送到远程存储库:

git push origin --tags

From the official Linux Kernel Git documentation for git push:

来自官方 Linux 内核 Git 文档git push

--tags

All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.

--tags

除了在命令行中明确列出的 refspecs 之外,refs/tags 下的所有 refs 都会被推送。

Or if you just want to push a single tag:

或者,如果您只想推送单个标签:

git push origin <tag>

See also my answer to How do you push a tag to a remote repository using Git?for more details about that syntax above.

另请参阅我对如何使用 Git 将标签推送到远程存储库的回答有关上述语法的更多详细信息。

Creating tags through GitHub's web interface

通过 GitHub 的 Web 界面创建标签

You can find GitHub's instructions for this at their Creating Releases help page. Here is a summary:

您可以在其创建发布帮助页面 中找到 GitHub 对此的说明。这是一个总结:

  1. Click the releaseslink on our repository page,

    Screenshot 1

  2. Click on Create a new releaseor Draft a new release,

    Screenshot 2

  3. Fill out the form fields, then click Publish releaseat the bottom,

    Screenshot 3Screenshot 4

  4. After you create your tag on GitHub, you might want to fetch it into your local repository too:

    git fetch
    
  1. 单击我们存储库页面上的发布链接,

    截图 1

  2. 单击Create a new releaseDraft a new release

    截图 2

  3. 填写表单字段,然后单击底部的发布版本

    截图 3截图 4

  4. 在 GitHub 上创建标签后,您可能还想将其提取到本地存储库中:

    git fetch
    

Now next time, you may want to create one more tag within the same release from website. For that follow these steps:

现在下一次,您可能希望在网站的同一版本中再创建一个标签。为此,请执行以下步骤:

Go to release tab

转到发布选项卡

  1. Click on edit button for the release

  2. Provide name of the new tag ABC_DEF_V_5_3_T_2 and hit tab

  3. After hitting tab, UI will show this message: Excellent! This tag will be created from the target when you publish this release. Also UI will provide an option to select the branch/commit

  4. Select branch or commit

  5. Check "This is a pre-release" checkbox for qa tag and uncheck it if the tag is created for Prod tag.

  6. After that click on "Update Release"

  7. This will create a new Tag within the existing Release.

  1. 单击发布的编辑按钮

  2. 提供新标签 ABC_DEF_V_5_3_T_2 的名称并点击选项卡

  3. 点击选项卡后,用户界面将显示此消息:太好了!当您发布此版本时,将从目标创建此标记。UI 还将提供一个选项来选择分支/提交

  4. 选择分支或提交

  5. 选中 qa 标记的“这是预发布”复选框,如果标记是为 Prod 标记创建的,则取消选中它。

  6. 之后点击“更新版本”

  7. 这将在现有版本中创建一个新标签。

回答by Lawakush Kurmi

Creating Tags

创建标签

Git uses two main types of tags: lightweightand annotated.

Git 使用两种主要类型的标签:轻量级和带注释的

Annotated Tags:

注释标签

To create an annotated tag in Git you can just run the following simple commands on your terminal.

要在 Git 中创建带注释的标签,您只需在终端上运行以下简单命令即可。

$ git tag -a v2.1.0 -m "xyz feature is released in this tag."
$ git tag
v1.0.0
v2.0.0
v2.1.0

The -m denotes message for that particular tag. We can write summary of features which is going to tag here.

-m 表示该特定标签的消息。我们可以在此处编写要标记的功能摘要。

Lightweight Tags:

轻量级标签

The other way to tag commits is lightweight tag. We can do it in the following way:

标记提交的另一种方法是轻量级标记。我们可以通过以下方式做到这一点:

$ git tag v2.1.0
$ git tag
v1.0.0
v2.0.0
v2.1.0

Push Tag

推送标签

To push particular tag you can use below command:

要推送特定标签,您可以使用以下命令:

git push origin v1.0.3

Or if you want to push all tags then use the below command:

或者,如果您想推送所有标签,请使用以下命令:

git push --tags

List all tags:

列出所有标签

To list all tags, use the following command.

要列出所有标签,请使用以下命令。

git tag

回答by kjdion84

You just have to push the tag after you run the git tag 2.0command.

您只需要在运行git tag 2.0命令后推送标签。

So just do git push --tagsnow.

所以git push --tags现在就做。

回答by Sylvernus Akubo

CAREFUL: In the command in Lawakush Kurmi's answer(git tag -a v1.0) the -aflag is used. This flag tells Git to create an annotated flag. If you don't provide the flag (i.e. git tag v1.0) then it'll create what's called a lightweight tag.

小心:在Lawakush Kurmi 的答案( git tag -a v1.0) 中的命令中-a使用了标志。这个标志告诉 Git 创建一个带注释的标志。如果您不提供标志 ( i.e. git tag v1.0),那么它将创建所谓的轻量级标签。



Annotated tags are recommended, because they include a lot of extra information such as:

建议使用带注释的标签,因为它们包含很多额外的信息,例如:

  • the person who made the tag
  • the date the tag was made
  • a message for the tag
  • 制作标签的人
  • 标签的制作日期
  • 标签的消息

Because of this, you should always use annotated tags.

因此,您应该始终使用带注释的标签。

回答by Nesha Zoric

It all depends what type of tag you want to create:

这完全取决于您要创建的标签类型:

  • If you want to create Annotated tags, to show extra metadata, you can do it in the following way: git tag -a v1.0.0.
  • On the other hand, Lightweight tags are used to "bookmark" your commits for private use: git tag v1.0.0.
  • 如果要创建带注释的标签,以显示额外的元数据,可以通过以下方式进行:git tag -a v1.0.0.
  • 另一方面,轻量级标签用于为您的提交“添加书签”以供私人使用:git tag v1.0.0.

There are a few other tag functionalities such as:

还有一些其他标签功能,例如:

  • Listing tags - git tag -l -n3. The command lists all existing tags with maximum 3 lines of their tag message. By default -n only shows the first line.
  • Tag details - git show <tag_identifier>. It shows all you need to know about a specific tag.
  • Sorting tags - git tag --sort=<type>
  • Publishing tags - git push origin v1.0. You can git push the tag individually, or you can run git push --tags which will push all tags at once.
  • 列出标签 - git tag -l -n3. 该命令列出所有现有标签,最多 3 行标签消息。默认 -n 只显示第一行。
  • 标签详情 - git show <tag_identifier>. 它显示了您需要了解的有关特定标签的所有信息。
  • 排序标签 - git tag --sort=<type>
  • 发布标签 - git push origin v1.0. 您可以单独 git push 标签,也可以运行 git push --tags 一次推送所有标签。

Be sure to check this tag related articlefor more relevant information.

请务必查看此标签相关文章以获取更多相关信息。

回答by Suresh Maidaragi

Using Sourcetree

使用源树

Here are the simple steps to create a GitHub Tag, when you release build from master.

当您从 master 发布构建时,以下是创建 GitHub Tag的简单步骤。

  1. Open source_tree tab

    step 1

  2. Right click on Tag sections from Tag which appear on left navigation section

    step 2

  3. Click on New Tag()

  4. A dialog appears to Add Tag and Remove Tag
  5. Click on Add Tag from give name to tag (preferred version name of the code)

    step 3

  6. If you want to push the TAG on remote, while creating the TAG ref: step 5 which gives checkbox push TAG to origincheck it and pushed tag appears on remote repository

  7. In case while creating the TAG if you have forgotten to check the box Push to origin, you can do it later by right-clicking on the created TAG, click on Push toorigin. enter image description here

  1. 开源_树选项卡

    第1步

  2. 右键单击出现在左侧导航部分的 Tag 中的 Tag 部分

    第2步

  3. 点击新标签()

  4. 出现一个对话框来添加标签和删除标签
  5. 单击从给定名称到标签的添加标签(代码的首选版本名称)

    第 3 步

  6. 如果要在远程推送 TAG,在创建 TAG 引用时:第 5 步将复选框推送 TAG 到源检查它并推送标签出现在远程存储库上

  7. 如果在创建 TAG 时忘记选中Push to origin框,您可以稍后通过右键单击创建的 TAG,单击Push toorigin 来完成。 在此处输入图片说明

回答by Gulab Bisht

For creating git tag you can simply run git tag <tagname>command by replacing with the actual name of the tag. Here is a complete tutorial on the basics of managing git tags: https://www.drupixels.com/blog/git-tags-create-push-remote-checkout-and-much-more

要创建 git 标签,您可以简单地git tag <tagname>通过替换为标签的实际名称来运行命令。以下是管理 git 标签基础知识的完整教程:https: //www.drupixels.com/blog/git-tags-create-push-remote-checkout-and-much-more