错误:src refspec与任何不匹配 [英] Error: src refspec does not match any

查看:65
本文介绍了错误:src refspec与任何不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GitLab中有几个朋友的项目,当然还有master分支,还有其他一些分支.克隆存储库时,我还使用命令 git remote add upper ... 创建了一个上游.

I have a project with a few friends in GitLab, and there is of course the master branch, and there are some others too. When I cloned the repository, I created also an upstream with the command git remote add upstream ....

然后,我发布了 git fetch上游.后跟 git checkout上行流/test1 .现在,如果输入 git branch -a ,我将得到如下输出:

Then, I issued the git fetch upstream. Followed by git checkout upstream/test1. Now, if I type git branch -a, I get an output like this:

* (HEAD detached at upstream/test1)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/upstream/test1
  remotes/upstream/master

这很好,但是后来我对 upstream/test1 分支中的代码做了一些更改,我想将它们推送到 origin/test1 存储库中,我收到标题上的错误消息.请注意,我按照以下步骤进行推送:

This is all fine, but then I did some changes to the code in my upstream/test1 branch, and I want to push them to origin/test1 repository, I get the error message on the title. Please note that I follow the steps below to push:

git add .
git commit -m "Sample message"
git push -u origin test1

如果发出 git show-ref ,则会得到以下输出:

If I issue git show-ref, I get the following output:

refs/heads/master
refs/remotes/origin/HEAD
refs/remotes/origin/master
refs/remotes/upstream/test1
refs/remotes/upstream/master

我检查了以下问题,但是没有找不到帮助.有任何解决方法的想法吗?

I checked the following questions, but didn't find it helpful. Any ideas how to solve it?

推荐答案

您似乎没有名为 test1 的本地分支.您有一个远程分支,名为 test1 ,与您的上游遥控器关联.

You don't appear to have a local branch named test1. You have a remote branch named test1 associated with your upstream remote.

您不应该直接编辑 upstream/test1 分支.实际上,尝试检查应该发出警告:

You shouldn't be editing the upstream/test1 branch directly. In fact, attempting to check that out should have yielded a warning:

$ git checkout upstream/test1

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

相反,您应该首先签出一个跟踪远程分支的本地分支,该分支应该看起来像这样:

You should instead first check out a local branch that tracks the remote branch, which ought to look something like this:

$ git checkout test1
Branch test1 set up to track remote branch test1 from upstream by rebasing.
Switched to a new branch 'test1'

执行完此操作后,未经修饰的 git push 会推送到 upstream 远程,而 git push origin test1 会推送到您的起源远程.在其中添加 -u 标志将切换跟踪分支,以便您的分支将跟踪 origin/test1 ,而不是跟踪 upstream/test1 ,因此默认情况下,将来的 git pull git push 操作将引用该远程分支( origin/test1 ).

After doing this, an undecorated git push would push to the upstream remote, while git push origin test1 would push to your origin remote. Adding the -u flag there would switch the tracking branch so that instead of tracking upstream/test1, your branch would track origin/test1, so that future git pull and git push operations would refer to that remote branch (origin/test1) by default.

这篇关于错误:src refspec与任何不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆