2012-06-21 193 views
2

我是github的新手。我一直在研究從github獲取的代碼。現在我完成了我的修改,並且希望將我的代碼推送到github。我想創建一個我工作過的原始代碼的分支,並將我的開發代碼推到那個分支上。然而,當我在開發工作時,原始代碼發生了一些變化。所以,當我試圖把我的新代碼叉我得到以下錯誤:如何將我的代碼推送到github fork

git push original master 
To https://github.com/<username>/<projectName>.git 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to 'https://github.com/<username>/<projectName>.git' 
To prevent you from losing history, non-fast-forward updates were rejected 
Merge the remote changes (e.g. 'git pull') before pushing again. See the 
'Note about fast-forwards' section of 'git push --help' for details. 

然後我用

git pull 

其輸出如下:

Pull is not possible because you have unmerged files. 
Please, fix them up in the work tree, and then use 'git add/rm <file>' 
as appropriate to mark resolution, or use 'git commit -a'. 

我可以」從這點開始繼續。我應該怎樣做我的項目?

回答

7

那麼,git告訴你該怎麼做。如果你想拉,你需要先完成不完整的合併。 Git status應該告訴你哪些文件尚未被合併。您需要解決合併衝突,然後在文件上使用git add來告訴git衝突已解決。這就是說,如果你的目標是去掉一個分叉,你應該先分叉代碼,克隆分叉的代碼,對它進行修改,然後把你的修改推回fork。完成後,您可以向原始項目的作者提交拉取請求以整合您的更改。

+1

他可以通過固定合併挽救他的提交,提交。然後將分叉的報告拖入另一個目錄,然後從本地目錄合併到本地目錄。然後推到他的叉子上。 –

-5

[危險]不要嘗試,如果你在一個團隊工作

試試這個。

git push -f original master 

始終節省了一天......

+3

強行推動是不好的做法,除非你想創造一些敵人,否則你應該避開它。 – peshkira

+0

我以爲他在單獨工作,而不是在Kernel.org上工作。 檢查了這一點,發生了什麼http://stackoverflow.com/a/432518/677185 –