git 无法推送到远程分支,无法解析到分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38034866/
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
Can't push to remote branch, cannot be resolved to branch
提问by jleach
I migrated my repos from Bitbucket or Github. I don't think this matters but it's the only thing different... For a little while I had two remotes set up:
我从 Bitbucket 或 Github 迁移了我的存储库。我认为这并不重要,但这是唯一不同的事情......有一段时间我设置了两个遥控器:
origin: bitbucket
github: github
Then I removed both and pointed origin to github:
然后我删除了两者并将原点指向github:
git remote remove origin
git remote remove github
git remote add origin https://github....
Test push of develop branch:
开发分支的测试推送:
git push origin develop
Everything up to date, ok, good.
一切都是最新的,好的,好的。
Create a new branch for some work as per usual:
像往常一样为一些工作创建一个新分支:
git checkout -b Feature/Name
Update a file or two. Attempt to push to remote:
更新一两个文件。尝试推送到远程:
git push origin Feature/Name
This results in the error:
这导致错误:
fatal: Feature/Name cannot be resolved to branch
致命:功能/名称无法解析为分支
Search online for this issue, find some stuff about ensuring HEAD is correct, others about making sure I've got my branch name case correct (though, at this point the branch doesn't exist on the remote yet). Unable to resolve.
在线搜索此问题,找到一些关于确保 HEAD 正确的内容,其他关于确保我的分支名称大小写正确的内容(尽管此时远程上尚不存在该分支)。无法解决。
Ran this command:
运行这个命令:
git push --all -u
This got my Feature/Name
branch to github, but still see same behavior as prior:
这让我的Feature/Name
分支转到了 github,但仍然看到与之前相同的行为:
git push origin develop
git push origin Feature/Name
The first works, the second throws the same error.
第一个有效,第二个抛出相同的错误。
I can't figure out why I'm getting this error. Any ideas?
我不明白为什么我会收到这个错误。有任何想法吗?
回答by Ty Le
I was having this issue as well, and it was driving me crazy. I had something like feature/name
but git branch -a
showed me FEATURE/name
. Renaming the branch, deleting and recreating it, nothing worked. What finally fixed it:
我也遇到了这个问题,这让我发疯了。我有类似feature/name
但git branch -a
给我看的东西FEATURE/name
。重命名分支,删除并重新创建它,没有任何效果。最终修复的是什么:
Go into .git/refs/heads
进入 .git/refs/heads
You'll see a FEATURE
folder. Rename it to feature
.
你会看到一个FEATURE
文件夹。将其重命名为feature
.
回答by Schwern
Based on my own testing and the OP's comments, I think at some point they goofed on the casing of the branch name.
根据我自己的测试和OP 的评论,我认为在某些时候他们在分支名称的大小写上犯了错误。
First, I believe the OP is on a case insensitive operating system like OS X or Windows. Then they did something like this...
首先,我相信 OP 是在不区分大小写的操作系统上,如 OS X 或 Windows。然后他们做了这样的事情......
$ git checkout -b SQLMigration/ReportFixes
Switched to a new branch 'SQLMigration/ReportFixes'
$ git push origin SqlMigration/ReportFixes
fatal: SqlMigration/ReportFixes cannot be resolved to branch.
Note the casing difference. Also note the error is very different from if you just typo the name.
注意外壳的不同。另请注意,该错误与您只是拼写名称的错误非常不同。
$ git push origin SQLMigration/ReportFixme
error: src refspec SQLMigration/ReportFixme does not match any.
error: failed to push some refs to '[email protected]:schwern/testing123.git'
Because Github uses the filesystem to store branch names, it tries to open .git/refs/heads/SqlMigration/ReportFixes
. Because the filesystem is case insensitive it successfully opens .git/refs/heads/SqlMigration/ReportFixes
but gets confused when it tries to compare the branch names case-sensitively and they don't match.
因为 Github 使用文件系统来存储分支名称,所以它尝试打开.git/refs/heads/SqlMigration/ReportFixes
. 因为文件系统不区分大小写,所以它成功打开,.git/refs/heads/SqlMigration/ReportFixes
但是当它尝试区分大小写比较分支名称并且它们不匹配时会感到困惑。
How they got into a state where the local branch is SQLMigration/ReportFixes
and the remote branch is SqlMigration/ReportFixes
I'm not sure. I don't believe Github messed with the remote branch name. Simplest explanation is someone else with push access changed the remote branch name. Otherwise, at some point they did something which managed to create the remote with the typo. If they check their shell history, perhaps with history | grep -i sqlmigration/reportfixes
they might be able to find a command where they mistyped the casing.
他们如何进入本地分支SQLMigration/ReportFixes
和远程分支的状态SqlMigration/ReportFixes
我不确定。我不相信 Github 弄乱了远程分支名称。最简单的解释是具有推送访问权限的其他人更改了远程分支名称。否则,在某些时候,他们做了一些事情,设法用错字创建了遥控器。如果他们检查他们的 shell 历史记录,也许history | grep -i sqlmigration/reportfixes
他们可以找到一个他们输入错误的命令。
回答by moggers
Git will let you checkout the current branch with a different casing, and it will fail to find a ref on the remote.
Git 会让你用不同的大小写检出当前分支,并且它无法在远程上找到 ref。
Just found out the hard way.
刚刚发现了困难的方法。
回答by JGL
A similar thing happened to me. I created a branch called something like "Feat/name". I tried to pushed it using :
类似的事情发生在我身上。我创建了一个名为“Feat/name”之类的分支。我尝试使用以下方法推送它:
git push --set-upstream origin Feat/name
git push --set-upstream origin 专长/名称
I got the same fatal error as you :
我遇到了和你一样的致命错误:
fatal: Feat/name cannot be resolved to branch
致命:专长/名称无法解析为分支
To solve it I created a new branch as I had very few files impacted. Then I listed my branches to delete the wrong one and it displayed with no cap :
为了解决这个问题,我创建了一个新分支,因为我的文件很少受到影响。然后我列出了我的分支以删除错误的分支,并且显示时没有上限:
- feat/name
- 专长/名字
I had used caps before but never on the first caracter. It looks like git doesn't like it...
我以前使用过大写字母,但从未在第一个字符上使用过。看起来git不喜欢它......
回答by Sherman Lye
It's case-sensitive, just make sure created branch and push to branch both are in same capital.
它区分大小写,只需确保创建的分支和推送到分支都在相同的资本中。
Example:
例子:
git checkout -b "TASK-135-hello-world"
WRONGway of doing:
错误的做法:
git push origin task-135-hello-world #FATAL: task-135-hello-world cannot be resolved to branch
CORRECTway of doing:
正确的做法:
git push origin TASK-135-hello-world
回答by jmojico
I solved this in Windows 10 by using cmdinstead of GitBash.
我在 Windows 10 中使用cmd而不是GitBash解决了这个问题。
It has to do with character case and how git and command lines handles them.
它与字符大小写以及 git 和命令行如何处理它们有关。
回答by Vee Trairattanapa
For my case, I used to have branch folder (or whatever it is called) with capital letters, then I create a new one with difference casing (lowercase) but git actually create the branch with capital.
就我而言,我曾经有大写字母的分支文件夹(或任何名称),然后我创建了一个具有不同大小写(小写)的新文件夹,但 git 实际上创建了大写的分支。
I have created a branch like feature-ABC/branch1
before and pushed it. Then I create a branch feature-abc/branch2
(notice the lower-case ABC), and try to push it to remote using git push --set-upstream origin feature-abc/branch2
and get the 'cannot be resolved to branch' error. So I git branch
and see that it actually created feature-ABC/branch2
instead of feature-abc/branch1
for me. I checkout again with git checkout feature-ABC/feature2
and push it using the uppercase (feature-ABC/feature2
) to solve it.
我像feature-ABC/branch1
以前一样创建了一个分支并推送了它。然后我创建一个分支feature-abc/branch2
(注意小写的 ABC),并尝试将它推送到远程使用git push --set-upstream origin feature-abc/branch2
并得到“无法解析为分支”错误。所以我git branch
看到它实际上feature-ABC/branch2
是feature-abc/branch1
为我而不是为我创建的。我再次结帐git checkout feature-ABC/feature2
并使用大写字母 ( feature-ABC/feature2
)推送它来解决它。
回答by Corbin Hudson
I faced the same issue which was due to going to branch with wrong casing. git let me switch to branch with incorrect casing ie feature/Name
instead of feature/name
. Found an easier solution than listed above just:
我遇到了同样的问题,这是由于要使用错误的大小写进行分支。git 让我切换到带有不正确大小写的分支,即feature/Name
而不是feature/name
. 找到了比上面列出的更简单的解决方案:
- commit your changes to 'feature/Name'
git checkout master (or develop)
git checkout feature/name
< with correct casinggit push
- 提交对“功能/名称”的更改
git checkout master (or develop)
git checkout feature/name
< 使用正确的大小写git push
回答by loko
You might have created similar branch but different case-sensitive-wise, then you have to run:
您可能已经创建了类似的分支,但区分大小写的方式不同,那么您必须运行:
git branch -D <name-of-different-case-branch>
git branch -D <name-of-different-case-branch>
and then try to push again.
然后再次尝试推动。
回答by joker
Maybe your forgot to run git fetch? it's required to fetch data from the remote repo! Try running git fetch remote/branch
也许你忘了运行 git fetch ?需要从远程仓库中获取数据!尝试跑步git fetch remote/branch