gpt4 book ai didi

git push local branch with same name as remote tag(与远程标记同名的git-push本地分支)

转载 作者:bug小助手 更新时间:2023-10-22 17:35:13 52 4
gpt4 key购买 nike



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

我正试图将一个新的本地分支产品-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

感谢您的投入


更多回答

Try refs/heads/product-0.2:refs/heads/product-0.2, i.e. without the leading slash, and also giving the full refspec on the local side.

试试refs/heads/product-0.2:refs/heads/product-0.2,即没有前导斜杠,也在本地提供完整的refspec。

Can try git push origin product-0.2:product-0.2

可以尝试git推送原产地产品-0.2:product-0.2

优秀答案推荐

The following command should work.

以下命令应该有效。



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


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]


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

如果你试图推送一个与分支同名的标签:



git push origin tag myTag


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:

发生这种情况是因为我意外地在本地创建了一个master标记:



$ git tag
master
tag1
tag2
tag3
tag4


Once I deleted this tag locally:

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



git tag -d master


I was able to push again.

我又能推了。



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 checkout on either a branch or a tag. Why would you fight with all these doubled up names? Change them.

但是,您可以对分支或标记执行git签出。你为什么要用这些双拼的名字打架?改变它们。



This failed :

此操作失败:



git push $origin $branch:$branch 


While this worked for me :

虽然这对我有效:



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


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



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

请再次尝试推送您的更改。现在这就行了。



Our team needed push the local branch to the repository with a TAG with the same name.

我们的团队需要将本地分支推送到具有相同名称的TAG的存储库。


This happen because, ARGO needs deploy an moodle apps , and not support build the
submodules directly, So another team created a TAG, when we really need a BRANCH.

发生这种情况是因为,ARGO需要部署一个moodle应用程序,而不支持直接构建子模块,所以另一个团队创建了一个TAG,当我们真正需要一个BRANCH时。


Steps:

步骤:



  1. pull repository from tag.

  2. git switch -c BRANCH

  3. git push --set-upstream origin BRANCH


Appear the error:

出现错误:


error: src refspec alt_v1.2.2 matches more than one
error: failed to push some refs to 'https://gitlab.com/SOME_URL.git'

错误:src refspec alt_v1.2.2匹配多个错误:无法将某些ref推送到“”https://gitlab.com/SOME_URL.git'


Solution:

解决方案:



  1. git tag -d alt_v1.2.2

  2. git push --set-upstream origin BRANCH


and problem solved !

问题解决了!



This could also happen if you have a tag and a branch with the same name and you try to push them without. Of course, GIT will be confused.

如果你有一个标签和一个同名的分支,而你试图在没有它们的情况下推送它们,也可能会发生这种情况。当然,GIT会感到困惑。



This is a bug. Impossible to browse a branch if a tag exists with the same name.

这是一个bug。如果存在具有相同名称的标记,则无法浏览分支。


更多回答

Accepted answer, this is the way to disambiguate. Still, it's way easier not to have tags and branches with the same name in the first place. Some tools (e.g. SourceTree) will stumble on it and you'll be left to your own devices, with the command line as the only solution. Thank you guys!

接受的答案,这是消除歧义的方法。尽管如此,一开始就不使用相同名称的标记和分支要容易得多。一些工具(例如SourceTree)会偶然发现它,您将只能使用自己的设备,命令行是唯一的解决方案。谢谢你们!

+1. A similar thing works when you need to disambiguate remote names: refs/remotes/remote_name/remote_branch

Had unknowingly named a tagged release master and could no longer push to the branch with the same name. git push origin refs/heads/master did the trick (then I deleted that tag so it'd stop happening).

在不知情的情况下命名了一个标记的发布主机,无法再推送到同名的分支。git push origin refs/heads/master做到了(然后我删除了那个标签,这样它就不会再发生了)。

Aside from best practices, you would still be unable to push branch you're trying to push to is the default branch.. How can we work around that?

除了最佳实践之外,您仍然无法推送您尝试推送到的分支是默认分支。。我们如何解决这个问题?

If the above solution does not work, please do it after removing the remote head. git push origin --delete refs/heads/BRANCHNAME

如果上述解决方案不起作用,请在卸下遥控头后进行。git推送原点--删除refs/heads/BRANCHNAME

Worked fine, had a tag with the same name as my branch.

工作很好,有一个和我的分支同名的标签。

I still get this: hint: Updates were rejected because the tag already exists in the remote.

我仍然得到这个:提示:更新被拒绝,因为标签已经存在于远程。

well done sir! this should be the accepted answer. always read the long tail SO answers

干得好,先生!这应该是公认的答案。总是读长尾SO答案

It's useful to know, but doesn't answer the question at all. I won't downvote it, since the author makes a point of emphasizing that it's the other way around, but hardly acceptable as the answer.

知道是有用的,但根本不能回答问题。我不会否决它,因为作者强调它是相反的,但作为答案很难被接受。

this should be accepting answer, I was looking for this command all my life

这应该是一个可以接受的答案,我一生都在寻找这个命令

Good explanation. Need to delete the local tag. Thanks!

很好的解释。需要删除本地标记。谢谢

if for some reason it matches more than one remote, you can delete the tag or head remote via: git push origin :refs/tags/tag1

如果由于某种原因,它匹配多个远程,您可以通过:git-push-origin:refs/tags/tag1删除标记或head-remote

I get this error: main -> refs/heads/main (already exists)

我得到这个错误:main->refs/heads/main(已经存在)

Should/could have called the tag product-0.2.0 with the last digit for the 'patch level' but still, we had the naming convention in place and we didn't run into trouble in the past when the branch was created before the tag.

本应/本可以用“补丁级别”的最后一位来调用标记product-0.2.0,但我们仍然有命名约定,而且在标记之前创建分支时,我们没有遇到麻烦。

If the team already started to use the branch would'nt it be armfull to rename it ?

如果团队已经开始使用分支,那么重命名它不是很明智吗?

Change the name of the entity you have not yet pushed.

更改尚未推送的实体的名称。

Are you sure about this @TheBuzzSaw? Because locally I can have both with same name, as different things.

你确定这个@TheBuzzSaw吗?因为在当地,我可以用相同的名字,作为不同的东西。

While the command (as selected answer) above may have resolved the question - being new to git I understood neither the question nor the answer. THIS answer at least gives a) advice and b) an explanation - even recommendation for the future. I would have considered asking my own question, but I tire of comments such as already asked before - imho: a question that is not understandable is not the same as a beginner question. But that is life ;)

虽然上面的命令(作为选定的答案)可能已经解决了这个问题——作为git的新手,我既不理解这个问题,也不理解答案。这个答案至少给出了a)建议和b)解释——甚至是对未来的建议。我本来会考虑问自己的问题,但我厌倦了之前已经问过的评论——imho:一个不可理解的问题与初学者的问题不同。但这就是生活;)

ssh: Could not resolve hostname head: nodename nor servname provided, or not known

ssh:无法解析主机名head:nodename或提供的servname,或者未知

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com