git 如何从标签创建新分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10940981/
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 13:52:51  来源:igfitidea点击:

How to create a new branch from a tag?

gitgit-branchgit-tag

提问by Andrew

I'd like to create a new master branch from an existing tag. Say I have a tag v1.0. How to create a new branch from this tag?

我想从现有标签创建一个新的主分支。说我有一个标签v1.0。如何从此标签创建新分支?

回答by Andrew

Wow, that was easier than I thought:

哇,这比我想象的要容易:

git checkout -b newbranch v1.0

回答by user1069067

If you simply want to create a new branch without immediately changing to it, you could do the following:

如果您只想创建一个新分支而不立即更改它,您可以执行以下操作:

git branch newbranch v1.0

回答by Tarun Kumar

I used the following steps to create a new hot fix branch from a Tag.

我使用以下步骤从标签创建新的热修复分支。

Syntax

句法

git checkout -b <New Branch Name> <TAG Name>

Steps to do it.

步骤来做。

  1. git checkout -b NewBranchName v1.0
  2. Make changes to pom / release versions
  3. Stage changes
  4. git commit -m "Update pom versions for Hotfix branch"
  5. Finally push your newly created branch to remote repository.
  1. git checkout -b 新分支名称 v1.0
  2. 更改 pom / 发布版本
  3. 舞台变化
  4. git commit -m "更新修补程序分支的 pom 版本"
  5. 最后将新创建的分支推送到远程存储库。
git push -u origin NewBranchName

I hope this would help.

我希望这会有所帮助。

回答by Kirtikumar A.

I have resolve the problem as below 1. Get the tag from your branch 2. Write below command

我已经解决了以下问题 1. 从你的分支中获取标签 2. 写在下面的命令

Example: git branch <Hotfix branch> <TAG>
    git branch hotfix_4.4.3 v4.4.3
    git checkout hotfix_4.4.3

or you can do with other command

或者你可以用其他命令

git checkout -b <Hotfix branch> <TAG>
-b stands for creating new branch to local 

once you ready with your hotfix branch, It's time to move that branch to github, you can do so by writing below command

一旦您准备好您的修补程序分支,就可以将该分支移动到 github,您可以通过编写以下命令来执行此操作

git push --set-upstream origin hotfix_4.4.3

回答by peterh - Reinstate Monica

The situation becomes a little bit problematic if we want to create a branch from a tag with the same name.

如果我们想从一个同名的标签创建一个分支,情况就会变得有点问题。

In this, and in similar scenarios, the important thing is to know: branches and tags are actually single-line text files in .git/refsdirectory, and we can reference them explicitly using their pathes below .git. Branches are called here "heads", to make our life more simple.

在这种情况下,在类似的情况下,重要的是要知道:分支和标签实际上是.git/refs目录中的单行文本文件,我们可以使用下面的路径明确引用它们.git。分支在这里被称为“头”,使我们的生活更简单。

Thus, refs/heads/masteris the real, explicit name of the masterbranch. And refs/tags/cicais the exact name of the tag named cica.

因此,refs/heads/mastermaster分支的真实、明确的名称。而refs/tags/cica被命名为标签的确切名称cica

The correct command to create a branch named cicafrom the tag named cicais:

创建以命名cica标签命名的分支的正确命令cica是:

git branch cica refs/tags/cica

回答by eranga

My branch list (only masternow)

我的分支列表(现在只有master

branch list

分行名单

My tag list (have three tags)

我的标签列表(有三个标签)

tag list

标签列表

Switch to new branch feature/codecfrom opus_codectag

opus_codec标签切换到新的分支功能/编解码器

git checkout -b feature/codec opus_codec

switch to branch

切换到分支