2017-07-29 212 views
2

我刚刚做了git remote remove origin并重新添加相同的远程原点。但是,只有在那之后我才意识到,我自己变成了一个情况,我不知道怎么追,因为这样做git remote remove origin之前,我有:git远程删除后,我的本地提交状态改变

$ git status 
On branch master 
Your branch is ahead of 'origin/master' by 5 commits. 
    (use "git push" to publish your local commits) 
nothing to commit, working tree clean 

但现在:

$ git status 
On branch master 
nothing to commit, working tree clean 

我现在应该怎么做?我怎样才能让git知道我的分支在5次提交之前领先于'origin/master'?谢谢。

+0

尝试'git fetch origin'。 –

回答

3

只需设置你的上游分支指向新origin

git branch --set-upstream-to origin/master 
+0

Thx!但我得到了'错误:请求的上游分支'origin/master'不存在'。做'git fetch'修复它。请更新答案。 – xpt

1

它只是删除与GIT的连接。你不需要担心任何事情,因为这只是连接丢失。你可以再次克隆,这是简单的解决方案。

我提供了确切的解决方案,我在下面检查解决您的问题。

当你做git remote remove origin时,.git目录下的config文件看起来像这样。

[core] 
    repositoryformatversion = 0 
    filemode = true 
    bare = false 
    logallrefupdates = true 
[branch "master"] 

当你再次让使用Git连接

git remote add origin [email protected]://github.com/userName/repoName 

再次创造git的连接,现在,你.git文件夹的config看起来像下面

[core] 
    repositoryformatversion = 0 
    filemode = true 
    bare = false 
    logallrefupdates = true 
[branch "master"] 
[remote "origin"] 
    url = [email protected]://github.com/userName/repoName 
    fetch = +refs/heads/*:refs/remotes/origin/* 

现在,您可以通过

添加 upstream
git remote add upstream https://github.com/userName/repoName 

git remote -v列出upstream, origin, master

现在,你可以从pullmaster(或fetchmerge)。我在这里直接pullgit pull https://github.com/userName/repoName

现在,一切正常。我检查了一切。