2012-06-21 194 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 –