2011-03-09 34 views
7

正當我想我得到了掛鉤的git checkout -b新分支 - 提交/提交/提交 - git checkout master - git merge newbranch - git rebase -i master - git push git中的工作流,東西爆炸了,我看不到任何理由。git本地主分支已停止跟蹤遠端/源/主,不能推

這裏的一般工作流程,這爲我在過去的工作:

# make sure I'm up to date on master: 
$ git checkout master 
$ git pull # k, no conflicts 
# start my new feature 
$ git checkout -b FEATURE9 # master @ 2f93e34 

Switched to a new branch 'FEATURE9' 

...作品,提交作品,提交作品,提交...

$ git commit -a 
$ git checkout master 
$ git merge FEATURE9 
$ git rebase -i master # squash some of the FEATURE9 ugliness 

到目前爲止,現在我希望看到 - 而平日裏看 - 是這樣的:

$ git status 

# On branch master 
# Your branch is ahead of 'origin/master' by 1 commit. 
# 
nothing to commit (working directory clean) 

但是,相反,我只看到「沒有提交(工作目錄乾淨)」,也沒有「你的分支是超前通過1的 '產地/主' 提交」,和git拉顯示了這種怪事:

$ git pull 
From .          # unexpected 
* branch   master  -> FETCH_HEAD # unexpected 
Already up-to-date.       # expected 

和Git分支-a -v顯示了這個:

$ git branch -a -v 

    FEATURE9     3eaf059 started feature 9 
* master     3eaf059 started feature 9 
    remotes/origin/HEAD  -> origin/master 
    remotes/origin/master 2f93e34 some boring previous commit # should=3eaf059 

git分支清楚地表明我目前在* master,並且git日誌清楚地表明master(local)在3eaf059,而remotes/origin/HEAD - > remotes/origin/master被卡在fork中。

理想情況下,我想知道我可能如何進入這個的語義,但我會解決一個辦法讓我的工作副本再次跟蹤遠程主人&讓兩人重新同步而不會失去歷史記錄。謝謝!

注:我再克隆回購在新目錄中並重新手動應用更改,一切工作正常,但我不希望出現這種情況是標準的解決辦法

附錄:標題顯示「無法推送」,但沒有錯誤消息。即使git branch -a -v顯示本地主服務器位於/遙控器/原點/主服務器之前,我也會收到「已更新」響應。下面是從混帳輸出拉遠程Git -v,分別爲:

$ git pull 
From . 
* branch   master  -> FETCH_HEAD 
Already up-to-date. 

$ git remote -v 
origin [email protected]:proj.git (fetch) 
origin [email protected]:proj.git (push) 

附錄2:它看起來好像我的本地主人被配置爲到遠程,但不從它拉。在做完for remote in 'git branch -r | grep -v master '; do git checkout --track $remote ; done之後,這裏是我的。看來我只是需要從主機再次從遙控/起源/主控制器,否?

$ git remote show origin 
* remote origin 
    Fetch URL: [email protected]:proj.git 
    Push URL: [email protected]:proj.git 
    HEAD branch: master 
    Remote branches: 
    experiment_f tracked 
    master tracked 
    Local branches configured for 'git pull': 
    experiment_f merges with remote experiment_f 
    Local refs configured for 'git push': 
    experiment_f pushes to experiment_f (up to date) 
    master pushes to master (local out of date) 
+1

你可以從'git remote -v'向你的問題添加輸出。 – 2011-03-09 09:19:58

+0

此外,您的問題標題指的是'push'的問題,但您沒有任何有關'push'的錯誤消息的信息。 – 2011-03-09 09:40:00

+1

您需要注意跟蹤遠程(即您的'master'分支)的重新綁定分支,因爲這會重寫歷史記錄,並且可能會混淆您自己或遠程存儲庫。如果你想壓縮提交,你可能想要在合併之前把它們擠壓在特性分支*上,直到你對它的操作更加自如。 – nickgrim 2011-03-09 10:28:58

回答

5

當你做一個git pull你真的想要做一個git push

由於某種原因,git pull從當前目錄「拉」,我懷疑你想從remotes/origin/HEAD拉。

git push origin產生什麼輸出?

[保羅附錄]:這使我得到了正確的答案,所以我接受。花弄清楚發生了什麼事情的額外步驟是:

# see details of the current config: 
$ git config -l 
branch.master.remote=. # uh oh, this should point to origin 
# to see what it should be ,make a clean clone of the same project 
# in a different directory, checkout the master branch and run the 
# same command. That showed "branch.master.remote=origin", so... 

# then to fix: 
$ git config branch.master.remote origin 

之後再次,本地主正在跟蹤的遙控器/產地/主。感謝Peter Farmer提供給我的線索!

+0

我的目標是在推送之前合併遠程更改以驗證構建。遙控器在我之前,但你的'git push origin'建議讓我嘗試了'git pull origin',這導致了「你要求從遠程'原點'拉動,但沒有指定 一個分支。而不是您當前分支的默認配置遠程 ,則必須在命令行上指定分支。「 'git pull origin master'帶來了一些東西,'git push origin'給了我「b1f6453..3b2d904 master - > master」。任何想法如何拉/推再次正確跟蹤遙控器? – 2011-03-09 19:17:31

1

做一些調查,從彼得和尼克的評論下面就導致:

# botched local clone: 
$ git config -l 
branch.master.remote=. 
branch.master.merge=refs/heads/master 
[...] 

# new/clean local clone: 
$ git config -l 
branch.master.remote=origin 
branch.master.merge=refs/heads/master 
[...] 

希望我能張貼此作爲一個答案不接受它(如果不是我將不得不刪除&把它放在一個評論或原始問題)。這樣做......

$ git config branch.master.remote origin 

...有branch.master.remote=origin了,但它並沒有解釋如何得到擺在首位「未跟蹤」。

如果有人能清晰地解釋:

一)怎麼我的地方「拙劣」回購可能都涌入給我的問題的工作流程這樣的狀態,並

B)的行動,以正確的順序安全地重新同步(鑑於遠程頭部可能在此期間先進),我想將其標記爲已接受的答案,因爲我認爲這對其他人在這種情況下最有用。

+0

我曾遇到過這種情況,但我並沒有試圖合併除本地分支以外的其他任何東西。知道是什麼原因導致這種變化是很好的。 – awm 2012-11-14 14:40:51