2017-07-29 213 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

現在,一切正常。我檢查了一切。