如何修复 git push 上的“无法解析为分支”?

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

How to fix "cannot be resolved to branch" on git push?

gitgithub

提问by Matt Kuhns

When I do a git status, I get my branch:

当我做 a 时git status,我得到了我的分支:

$ git status
On branch OfflineLoading

When I tried to git push, I get:

当我尝试时git push,我得到:

$ git push origin OfflineLoading
fatal: OfflineLoading cannot be resolved to branch.

When I check the branches, it is not there:

当我检查分支时,它不存在:

$ git branch
   branch1
   branch2
   branch3
   branch4

How do I fix this?

我该如何解决?

回答by Kyle

The common issue is case mistake. I got the same issue before. The better way to do it is to check what are the branch names:

常见的问题是大小写错误。我之前也遇到过同样的问题。更好的方法是检查分支名称是什么:

$ git branch
  master
 *branch1
  Branch2

you can compare the branch on above, then push it with the name you got.

你可以比较上面的分支,然后用你得到的名字推送它。

$ git push origin Branch2

or

或者

$ git push origin branch1

回答by Sueii

In addition to Kyle's answer,

除了凯尔的回答,

In cases where you already have a branch name like "BugFix/item001" and pushed it to your repository, and then you created another branch with the name "Bugfix/item002", you will still get the same error even if you try to push the branch with the correct casing. I believe this is because of the "BugFix" folder being created already and future branches will use the same folder.

在情况下,你已经有了一个分支名称,如“虫˚FIX / item001”,并将其推到你的资料库,然后创建一个名为“虫另一个分支˚FIX / item002”,你仍然会得到同样的错误,即使您尝试使用正确的外壳推动分支。我相信这是因为已经创建了“BugFix”文件夹,未来的分支将使用相同的文件夹。

It is still a casing mistake but really misleading.

这仍然是一个大小写错误,但确实具有误导性。