git pull 显示“fatal: 找不到远程 ref refs/heads/xxxx”并挂断

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

git pull displays "fatal: Couldn't find remote ref refs/heads/xxxx" and hangs up

git

提问by mdesantis

I created a branch called '6796', then I pushed it to remote, checked it out on another machine, made other edits, pushed it, then merged it with the master, and deleted it - locally and remotely (git push :6796) - on the other machine. Now, when I run git pull:

我创建了一个名为“6796”的分支,然后将其推送到远程,在另一台机器上检查它,进行其他编辑,推送它,然后将其与主服务器合并,然后将其删除 - 本地和远程 ( git push :6796) - 在另一台机器上机器。现在,当我运行时git pull

fatal: Couldn't find remote ref refs/heads/6796
user@host:~/path/to/repo$ fatal: The remote end hung up unexpectedly

but git pull origin masterworks normally. It seems to me that there is some 6796 reference hang up... how to resolve this?

git pull origin master工作正常。在我看来,有一些 6796 参考挂断了......如何解决这个问题?

回答by Karl Bielefeldt

There are probably some commands to resolve it, but I would start by looking in your .git/configfile for references to that branch, and removing them.

可能有一些命令可以解决它,但我首先会在您的.git/config文件中查找对该分支的引用,然后将其删除。

回答by jweyrich

You also have to delete the local branch:

您还必须删除本地分支:

git branch -d 6796

Another way is to prune all stale branches from your local repository. This will delete all local branches that already have been removed from the remote:

另一种方法是从本地存储库中修剪所有陈旧的分支。这将删除已从远程删除的所有本地分支:

git remote prune origin --dry-run

回答by santiaago

I had a similar issue when I tried to get a pull with a single quote ' in it's name.

当我试图在名称中使用单引号 ' 进行拉取时,我遇到了类似的问题。

I had to escape the pull request name:

我不得不转义拉取请求名称:

git pull https://github.com/foo/bar namewithsingle"'"quote

回答by ikaruss

This error could be thrown in the following situation as well.

在以下情况下也可能抛出此错误。

You want to checkout branch called featurefrom remote repository but the error is thrown because you already have branch called feature/<feature_name>in your local repository.

您想签feature出从远程存储库调用的分支,但由于您已经feature/<feature_name>在本地存储库中调用了分支,因此会引发错误。

Simply checkout the featurebranch under a different name:

只需feature以不同的名称签出分支:

git checkout -b <new_branch_name> <remote>/feature

回答by L_7337

I just ran into a similar issue when I tried to commit to a newly created repo with a "."in it's name. I've seen several others have different issues with putting a "." in the repo name.

当我尝试使用“.”提交新创建的存储库时,我遇到了类似的问题以它的名义。我已经看到其他几个人对放置“.”有不同的问题。在回购名称中。

I just re-created the repo and

我刚刚重新创建了 repo 和

replaced "." with "-"

There may be other ways to resolve this, but this was a quick fix for me since it was a new repo.

可能还有其他方法可以解决这个问题,但这对我来说是一个快速解决方案,因为它是一个新的存储库。

回答by polyccon

To pull a remote branch locally, I do the following:

要在本地拉取远程分支,我执行以下操作:

git checkout -b branchname// creates a local branch with the same name and checks out on it

git pull origin branchname// pulls the remote one onto your local one

git checkout -b branchname// 创建一个同名的本地分支并签出它

git pull origin branchname// 将远程的拉到本地的

The only time I did this and it didn't work, I deleted the repo, cloned it again and repeated the above 2 steps; it worked.

唯一一次我这样做但它不起作用,我删除了repo,再次克隆它并重复上述2个步骤;有效。