git 切换回空的主分支时上游消失的消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24870145/
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
Upstream gone message on switching back to an empty master branch?
提问by DolphinJava
My git version is Git-1.9.4-preview20140611 Earlier, I cloned an empty git origin repository. The repository cloned but with following message
我的git版本是Git-1.9.4-preview20140611 之前我克隆了一个空的git origin仓库。存储库已克隆,但带有以下消息
warning: You appear to have cloned an empty repository. Checking connectivity... done.
警告:您似乎克隆了一个空存储库。检查连通性...完成。
Next, copied a .gitIgnore file which was in another project's master Git repository and committed it to the local master. This file has been used by us for many times before. This seems fine. We have a standardized .gitIgnore file for all our projects. This was created as part of best practices.
接下来,复制另一个项目的 master Git 存储库中的 .gitIgnore 文件并将其提交给本地 master。我们之前多次使用过这个文件。这似乎很好。我们所有的项目都有一个标准化的 .gitIgnore 文件。这是作为最佳实践的一部分创建的。
Next created a new branch and copied some code in the physical location where local git repo resides
接下来创建了一个新分支,并在本地 git repo 所在的物理位置复制了一些代码
git checkout -b FromCC
Added the code and committed in this branch.
添加代码并在此分支中提交。
git add --all
git commit -M "Blah"
All these operations are successful.
所有这些操作都是成功的。
My purpose is to merge these changes eventually into local master branch.
我的目的是将这些更改最终合并到本地 master 分支中。
I next do
我接下来做
git checkout master
and get following message.
并收到以下消息。
Your branch is based on 'origin/master', but the upstream is gone. (use "git branch --unset-upstream" to fixup)
您的分支基于“origin/master”,但上游已经消失。(使用“git branch --unset-upstream”来修复)
What does this message mean? Why would upstream 'go away' ?
这个消息是什么意思?为什么上游会“消失”?
Interesting observation: I repeated the same process with the same master Git repository today. This time the Git repository was not empty. It had .gitIgnore file before hand. This time fore-mentioned message did not appear.
有趣的观察:我今天在同一个主 Git 存储库中重复了相同的过程。这次 Git 仓库不是空的。它事先有 .gitIgnore 文件。这次没有出现上述消息。
回答by torek
It's not the upstream repository(origin
itself) but rather the specific branch you cloned (master
on origin) that is missing.
丢失的不是上游存储库(origin
本身),而是您克隆(master
在源上)的特定分支。
Moreover, git's message is misleading: the branch master
on origin did not go away, it was never there. When you cloned the empty repository, it had no branches at all. It continued to have no branches. Hence, your local master
, which was set to track origin/master
, was (is) tracking a branch that did (does) not exist.
此外,git 的信息具有误导性:master
origin 上的分支没有消失,它从未存在过。当您克隆空存储库时,它根本没有分支。它继续没有分支。因此,您master
设置为 track 的localorigin/master
正在(正在)跟踪确实(不)存在的分支。
The message is meant more for a situation like this:
该消息更适用于这样的情况:
$ git clone ...
$ git checkout featureX # track some feature branch
[go away for a week, come back]
$ git fetch -p # update remote branches
where, during that week you were away, the featureX
branch was deleted (presumably merged into its development line and then no longer needed). At this point you're on a local branch, featureX
, set to track remote-branch origin/featureX
, but there is no origin/featureX
any more.
在你离开的那一周,featureX
分支被删除了(大概合并到它的开发线然后不再需要)。此时您在本地分支上,featureX
设置为跟踪 remote-branch origin/featureX
,但没有origin/featureX
其他分支了。
In this case, though, you have local branch master
tracking origin/master
when there is no origin/master
yet. Once you create it (via the push that makes the repository non-empty), the problem will go away. This cropped up only because by default you start with master
even if the remote is empty and does not actually have a master
yet.
在这种情况下,虽然,你有地方分支master
跟踪origin/master
时,有没有origin/master
还。一旦你创建了它(通过使存储库非空的推送),问题就会消失。这只是因为默认情况下master
即使遥控器为空并且实际上还master
没有。
回答by R. Maurer
I came across this after creating a completely empty repo on github and git clone
d to local. Including the warning about an empty repo. Then a commit
for a newly created local file gave the message regarding "upstream is gone".
我在 github 上创建了一个完全空的 repo 并git clone
在本地创建了d后遇到了这个问题。包括关于空回购的警告。然后commit
,新创建的本地文件的 a 给出了有关“上游已消失”的消息。
To fix it and to use the remote upstream repo for this case:
要修复它并在这种情况下使用远程上游存储库:
git push -u origin master
git push -u origin master
- This transfers the locally existing master to the remote github repo.
- The -u switch to push does set the upstream (long version is --set-upstream) to the set on github.
- 这会将本地现有的 master 传输到远程 github repo。
- push 的 -u 开关确实将上游(长版本是 --set-upstream)设置为 github 上的集合。
Message is gone as the master branch now is also available on the remote repo.
消息消失了,因为 master 分支现在也可以在远程仓库上使用。
回答by Kaspars Rinkevics
I had same error message with github. The actual problem was that I had not approved invitation to the repository. So the git thought I did not have the rights for the repo.
我与 github 有相同的错误消息。实际问题是我没有批准对存储库的邀请。所以 git 认为我没有 repo 的权利。