2013-07-02 48 views
-1

我正在研究一個名爲'master'的分支。有人從原點刪除它,現在我處於一個奇怪的狀態,我無法提交我的更改。我想將它們提交給新的'stable'分支。git遠程分支在我工作時被刪除

我試過以下關於stackoverflow的一些說明,現在我真的搞砸了。

$ git log --oneline --decorate --graph --all -10 
* 4b2b148 (HEAD, origin/stable, stable) move from master branch 
| * 1be25fe (origin/master, origin/HEAD, next, master) require pcre to prevent regular expression weirdness 

1be25fe是我想要應用於stable的提交。 4b2b148是我犯的一些奇怪的東西。如何讓1be25fe穩定並完全刪除4b2b148?

+1

僅僅因爲他們從原點刪除它並不意味着它會從您的本地存儲庫中刪除。如果推送更改,分支將在上游重新創建。 –

+0

它不會讓我推或拉。更新被拒絕,因爲推送的分支尖端位於其對應的遠程 之後。檢查此分支併合並遠程更改 (例如'git pull'),然後再次推送。 – jsd

+0

請編輯該問題來描述實際情況。遙控器不能將分支刪除並同時在前方,可以嗎? –

回答

1

要恢復到1be25fe,您需要運行以下命令,將HEAD移回1be25fe。然後,您可以通過執行推送來推動上游。

git reset --hard 1be25fe # revert back to 1be25fe 
git status    #to check to see that it has reverted correctly, and see if there are any other issues. 
git push origin stable #push the changes and recreated the branch upstream 

//編輯

要避開你的「尖」的背後是錯誤,你可以在-f參數添加到推。此參數強制遠程存儲庫中的更改。我早些時候遇到了同樣的問題,並且完美地工作。

git push -f origin stable 

//編輯2

如果你想真正刪除提交,你需要看墊底:http://git-scm.com/book/en/Git-Branching-Rebasing

//編輯3

要合併與4b2b148變化,您需要執行以下操作:

git checkout -b important_changes origin/stable # branch off from the current state 
git cherry-pick 4b2b148 # retrieve the commit containing the changes and insert it ahead of 1be25fe 
git checkout stable # switch back to the older branch 
git merge important_changes # merge in the important changes 
git commit -am 'merged important changes' # commit the changes 
git push origin stable # push the branch to master 
git branch -d important_changes # remove the temp branch. 

警告:您m當合並important_changesstable時,您可能會遇到一些合併問題。確保在推送前它們已被固定。

+0

錯誤:未能將某些參考推送到ssh://git.server.com:7999/TM/repo.git' 提示:由於當前分支的提示位於 之後,更新被拒絕提示:其遠程對方。合併遠程更改(例如'git pull') 提示:再次推送之前。 提示:有關詳細信息,請參閱'git push --help'中的'關於快速轉發的注意事項'。 – jsd

+0

@jsd我已更新答案。 –

+0

啊,這次git pull實際工作。它之前沒有這樣做。謝謝 – jsd