关于切换回空的主分支的上游消息? [英] Upstream gone message on switching back to an empty master branch?

查看:44
本文介绍了关于切换回空的主分支的上游消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的git版本是Git-1.9.4-preview20140611之前,我克隆了一个空的git origin仓库.克隆了存储库,但显示以下消息

My git version is Git-1.9.4-preview20140611 Earlier, I cloned an empty git origin repository. The repository cloned but with following message

警告:您似乎已克隆了一个空的存储库.正在检查连通性...已完成.

接下来,复制一个.gitIgnore文件,该文件位于另一个项目的主Git存储库中,并将其提交给本地主文件.这个文件已经被我们使用了很多次.好像很好我们所有项目都有一个标准化的.gitIgnore文件.这是最佳做法的一部分.

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.

下一步创建了一个新分支,并在本地git repo所在的物理位置复制了一些代码

Next created a new branch and copied some code in the physical location where local git repo resides

git checkout -b FromCC

添加了代码并提交到该分支.

Added the code and committed in this branch.

git add --all
git commit -M "Blah"

所有这些操作均成功.

我的目的是最终将这些更改合并到本地master分支中.

My purpose is to merge these changes eventually into local master branch.

我接下来要做

git checkout master

并获得以下消息.

您的分支基于起源/母版",但上游已消失.(使用"git branch --unset-upstream"进行修复)

Your branch is based on 'origin/master', but the upstream is gone. (use "git branch --unset-upstream" to fixup)

此消息是什么意思?为什么上游会消失"?

What does this message mean? Why would upstream 'go away' ?

有趣的观察:今天,我对相同的主Git存储库重复了相同的过程.这次,Git存储库不为空.它之前有.gitIgnore文件.这次没有出现上述消息.

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.

推荐答案

它不是上游存储库(本身是 origin ),而是您克隆的特定分支(原点上的).

It's not the upstream repository (origin itself) but rather the specific branch you cloned (master on origin) that is missing.

此外,git的消息具有误导性:起源处的分支 master 并未消失,它从未出现过 .克隆空存储库时,它根本没有分支.它继续没有分支.因此,您的本地 master (设置为跟踪 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.

该消息在以下情况下更有意义:

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

在您离开的那一周中, featureX 分支被删除了(可能合并到其开发线中,然后不再需要).此时,您在本地分支 featureX 上,该分支设置为跟踪远程分支 origin/featureX ,但是没有 origin/featureX 更多.

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.

但是,在这种情况下,当还没有 origin/master 时,您有本地分支 master 跟踪 origin/master .一旦创建了它(通过使存储库为非空的推送),问题就会消失.之所以出现这种情况,是因为默认情况下,即使遥控器是空的并且实际上还没有 master ,您还是从 master 开始.

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.

这篇关于关于切换回空的主分支的上游消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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