当涉及到git的高级操作时,我更像是一个新手。我使用博客框架Octopress来维护我的博客。虽然Octopress自2011年以来没有任何开发,但它很好地满足了我的目的,所以到目前为止我还没有想过要改变任何东西。

仅供参考,我的博客托管在Github Pages上。

今天,在工作在一个新的帖子,git状态显示以下消息:

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

所有后续命令都重复相同的消息,如git add ., git commit -m 'message'和git push origin source。

这条信息是什么意思? 有什么东西坏了吗? 如果是,是什么? 我需要修理它吗?

如果可能的话,请给我一个pdf/网络文章,在那里我可以阅读这一点,并理解它的未来。

更多的细节:

bash-3.2$ git branch -a
* source
  remotes/octopress/2.1
  remotes/octopress/HEAD -> octopress/master
  remotes/octopress/gh-pages
  remotes/octopress/linklog
  remotes/octopress/master
  remotes/octopress/refactor_with_tests
  remotes/octopress/rubygemcli
  remotes/octopress/site
  remotes/origin/source

如果还需要更多信息,请告诉我。谢谢。


当前回答

问题:你的分支基于“起源/主”,但上游已经没有了。

解决方案:git分支——unset-upstream

其他回答

问题:你的分支基于“起源/主”,但上游已经没有了。

解决方案:git分支——unset-upstream

我遇到过两次这个问题,而且总是由我本地分支的git缓存文件损坏引起的。我通过将缺失的提交散列写入该文件来修复它。我从服务器上获得了正确的提交散列,并在本地运行了以下命令:

cat .git/refs/remotes/origin/feature/mybranch \
echo 1edf9668426de67ab764af138a98342787dc87fe \
>> .git/refs/remotes/origin/feature/mybranch

torek的答案可能是完美的,但我只是想提一个与原始问题中描述的不同,但可能出现相同错误的情况(因为它可能会帮助其他有类似问题的人):

我已经在我的一个服务器上使用git init -bare创建了一个空(新)repo。然后我将git克隆到我PC上的本地工作区。

在本地回购上提交一个版本后,我在调用git状态后得到了这个错误。

根据torek的回答,我明白发生了什么,第一次提交本地工作目录repo创建了“主”分支。但是在远程回购(在服务器上)从来没有任何东西,所以甚至没有一个“主”(remotes/origin/master)分支。

在运行git从本地repo推送origin master后,远程repo终于有了一个主分支。这阻止了错误的出现。

所以总结一下——一个新的远程回购可能会得到这样一个零提交的错误,因为它没有分支,包括“master”。

Actually torek told you already how to use the tools much better than I would be able to do. However, in this case I think it is important to point out something peculiar if you follow the guidelines at http://octopress.org/docs/deploying/github/. Namely, you will have multiple github repositories in your setup. First of all the one with all the source code for your website in say the directory $WEBSITE, and then the one with only the static generated files residing in $WEBSITE/_deploy. The funny thing of the setup is that there is a .gitignore file in the $WEBSITE directory so that this setup actually works.

足够的介绍。在这种情况下,错误也可能来自_deploy中的存储库。

cd _deploy

git branch -a
* master
remotes/origin/master
remotes/origin/source

在.git/config中,你通常需要找到这样的东西:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@github.com:yourname/yourname.github.io.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

但在您的情况下,分支管理员没有遥控器。

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@github.com:yourname/yourname.github.io.git
    fetch = +refs/heads/*:refs/remotes/origin/*

你可以通过以下方法来解决:

cd _deploy
git branch --set-upstream-to=origin/master

所以,一切都像torek告诉你的那样,但可能需要指出的是,这很可能涉及到_deploy目录,而不是你的网站的根目录。

PS:使用带有git插件的shell(如zsh)来避免将来被这个东西咬伤可能是值得的。它将立即显示_deploy涉及不同的存储库。

这是最简单的解决方案,你只要把git分支——unset-upstream,如果你在git push之前输入git状态,在commit之后你会看到你的分支是基于'origin/main'的,但是upstream已经没有了。(使用“git branch——unset-upstream”来修复)希望能有所帮助

图片说明