如何从远程标签执行“git checkout -b <branchname>”

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

How to do a "git checkout -b <branchname>" from a remote tag

gitgit-branch

提问by Sergi

I'm trying to create a branch from a remote tag, but it seems there's no way to do it. When I try

我试图从远程标签创建一个分支,但似乎没有办法做到这一点。当我尝试

git checkout -b test origin/deploy

where origin is the remote and deploy is the tag I want to check out, but I get

其中 origin 是远程,deploy 是我想检查的标签,但我得到

fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/deploy' which can not be resolved as commit?

UPDATE:I've just discovered that

更新:我刚刚发现

git fetch --all -t

was not working properly for me. While it downloads all branches, it does not download all tags, so when I checked out deploy it was and old tag. Now I execute

对我来说工作不正常。当它下载所有分支时,它不会下载所有标签,所以当我检查部署时它是旧标签。现在我执行

git fetch --all && git fetch -t

This way when I create a new branch based on a tag

这样当我基于标签创建新分支时

git checkout -b test deploy

the new branch is up to date with the last deploy.

新分支与上次部署保持同步。

采纳答案by Sk?ggiga Mannen

I'm not a git guru, but I had used something like this before and it seemed to have worked fine:

我不是 git 大师,但我以前使用过类似的东西,它似乎工作得很好:

git pull (or fetch, just need to make sure you are updated)
git checkout -b test remotes/origin/deploy

回答by Joost Diepenmaat

I'm not sure you can do this directly. You're probably stuck with doing a fetch and then a checkout:

我不确定您是否可以直接执行此操作。您可能会坚持执行提取然后结帐:

git fetch origin
git checkout -b test tag-name

By the way, I wouldn't recommend using a tag name like "deploy".

顺便说一下,我不建议使用像“deploy”这样的标签名称。

回答by Nagaraj N Hittalamani

You need to run

你需要跑

git pull
git checkout -b <new-branch-name> remotes/origin/<source-branch-name>

回答by Ovi

to list all the tags

列出所有标签

git fetch
git tags -l 

to create a local branch that points to the tag

创建一个指向标签的本地分支

git checkout tags/<tag_name> -b <branch_name>
git checkout -b <branch_name> tags/<tag_name>