2015-07-06 29 views
3

我通常使用此命令git的結帳分支,但仍然在主

git fetch && git checkout branch 

之後轉分支,我通常會檢查我的工作我通過git info旨在分支,這將突出地方分公司我正在工作(在分支名稱旁邊帶有星號*)。

我今天遵循同樣的模式,但不知何故混帳保持分支,我跑git fetch && git checkout branch即使經過。從命令行有沒有錯誤日誌。但在此之後,git info顯示類似的東西(本地分支仍然,而不是分支線程,我想切換到)。

## Remote Branches: 

    origin/HEAD -> origin/master 
    origin/master 
    origin/threads 

    ## Local Branches: 

    * master 

比較正常的情況下(當如預期git checkout branch作品) - 奇怪的事情似乎是有兩個origin/master,第一origin/HEAD -> origin/master似乎正常;我不確定第二個。

在這裏有一些奇怪的東西,但我還沒有想出。

+0

難道'git fetch'失敗了嗎? – kostya

+0

我發佈'git fetch',但也沒有錯誤日誌。 – artm

+0

你似乎沒有'origin/threads'的本地跟蹤分支 - 你有沒有在這個特定的分支中使用它,在這個特定的回購實例中? – Useless

回答

1

它看起來像我有一個分歧的主人。

奇怪的是,這個命令沒有顯示任何錯誤日誌。

$ git fetch && git checkout threads # threads is the name of the branch 

但是,

$ git fetch && git checkout master 
    Switched to branch 'master' 
    Your branch and 'origin/master' have diverged, 
    and have 7 and 3 different commits each, respectively. 
    (use "git pull" to merge the remote branch into yours) 

,並

$ git pull origin master 
    From <git_repo>  # <git_repo> is the URL of the repo 
    * branch   master  -> FETCH_HEAD 
    Auto-merging <file> # <file> is the filename in question 
    CONFLICT (add/add): Merge conflict in <file> 
    Automatic merge failed; fix conflicts and then commit the result. 

後,我手動解決上衝突,現在git fetch && git checkout threads工作正常,我可以切換到分支線程

至於爲什麼我第一次得到分歧主,我不確定 - 可能是因爲我的一些git rebase命令沒有做好。

0

請注意,git fetch只會根據您的.git/config文件中的配置拉動參考 - 它可能沒有達到您的預期。如果你還沒有設置遠程追蹤分支,那麼它不知道從遠程分支拉下來的東西。

此外,'git checkout master'將始終切換到您的分支,稱爲主分支,而不是遠程主分支。所以你創建了一個名爲'master'的分支上面的分支根本不會改變它。