git push 与远程标签同名的本地分支

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

git push local branch with same name as remote tag

gitgit-branch

提问by youri

I'm trying to push a new local branch product-0.2to remote where there is already a tag with the same name (but the branch itself does not exist)

我正在尝试将一个新的本地分支推product-0.2送到已经有同名标签的远程(但分支本身不存在)

git push -v --tags --set-upstream origin product-0.2:product-0.2 
Pushing to https://****@github.com/mycompany/product.git
error: src refspec product-0.2 matches more than one.
error: failed to push some refs to 'https://****@github.com/mycompany/product.git'

Same with:

同:

git push origin product-0.2:/refs/heads/product-0.2 

Although the other way around it works, e.g. create a branch product-0.1, commit on it then apply a tag product-0.1.

尽管它的另一种方法是有效的,例如创建一个分支product-0.1,提交它然后应用一个标签product-0.1

Some people work around this by removing the conflicting tag locally, then push the branch, then retrieve the remote tag, but it seems cumbersome and error prone.

有些人通过在本地删除冲突标签来解决这个问题,然后推送分支,然后检索远程标签,但这似乎很麻烦且容易出错。

How can I create my branch with minimal fuss?

如何以最小的麻烦创建我的分支?

Thanks for your input

感谢您的输入

回答by ralphtheninja

The following command should work.

以下命令应该可以工作。

git push origin refs/heads/product-0.2:refs/heads/product-0.2 

回答by ecairol

Verify what tags are associated with your branch:

验证哪些标签与您的分支相关联:

git tag

In my case, I had a tag with the same name of the branch. Deleting it worked:

就我而言,我有一个与分支名称相同的标签。删除它有效:

git tag -d [tag-name]

回答by TheBuzzSaw

Change the names.

更改名称。

Whether you do it locally or remotely, just change the names.

无论您是在本地还是远程进行,只需更改名称即可。

A tag and a branch are fundamentally the same thing in git: they represent a pointer to a commit. The difference is that a branch pointer advances as you make commits, while a tag remains static.

标签和分支在 git 中本质上是一样的:它们代表一个指向提交的指针。不同之处在于分支指针在您提交时前进,而标签保持静态。

However, you can perform a git checkouton either a branch or a tag. Why would you fight with all these doubled up names? Change them.

但是,您可以git checkout对分支或标记执行 a 。你为什么要和所有这些双倍的名字打架?改变它们。

回答by Paulo Merson

If you're trying to push a tagthat has the same name of a branch:

如果您尝试推送与分支具有相同名称的标签

git push origin tag myTag

回答by Jasbeer Rawal

I was trying to push to a canonical repository this morning and got the following error:

今天早上我试图推送到规范存储库并收到以下错误:

$ git push origin master
error: src refspec master matches more than one.
error: failed to push some refs to 'ssh://user@host/srv/git/repo'

This happened because I had accidentally created a master tag locally:

发生这种情况是因为我不小心在本地创建了一个主标签:

$ git tag
master
tag1
tag2
tag3
tag4

Once I deleted this tag locally:

一旦我在本地删除了这个标签:

git tag -d master

I was able to push again.

我能够再次推动。

回答by RzR

This failed :

这失败了:

git push $origin $branch:$branch 

While this worked for me :

虽然这对我有用:

git checkout $branch
git push $origin HEAD:$branch

回答by Muhammad Bilal

If you are using source tree then follow the following steps.

如果您使用的是源代码树,请按照以下步骤操作。

  1. find the Tag name of branch in tags section
  2. click on Tag name delete tag.
  3. Make sure you check "remove tags from remote" and click ok
  1. 在标签部分找到分支的标签名称
  2. 点击标签名称删除标签。
  3. 确保选中“从远程删除标签”并单击“确定”

Try again to push your changes. now this will work.

再次尝试推送您的更改。现在这将起作用。