git 如何将我的代码推送到 github fork
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11143688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to push my code to github fork
提问by polerto
I am new to github. I have been working on a code that I fetched from github. Now I completed making my modifications and I want to push my code to github. I would like to create a fork of the original code that I worked on and push my developed code over that fork. However while I was working on development there has been some changes at the original code. So when I try to push my new code to the fork I get the following error:
我是 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.
Then I used
然后我用
git pull
which outputted the following:
输出以下内容:
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'.
I can't continue from this point on. What should I do to commit my project?
从现在开始我不能继续了。我应该怎么做才能提交我的项目?
回答by wadesworld
Well, git is telling you what to do. If you want to pull, you need to finish the incomplete merge first. Git status
should tell you what files are as yet unmerged. You need to resolve the merge conflicts and then use git add
on the file(s) to tell git that the conflict is resolved.
好吧,git 告诉你该怎么做。如果要拉取,需要先完成不完全合并。 Git status
应该告诉您哪些文件尚未合并。您需要解决合并冲突,然后git add
在文件上使用以告诉 git 冲突已解决。
With that said, if your goal is to work off a fork, you should fork the code first, clone the forked code, make your modifications to it, and then push your changes back to the fork. Once that's done, you can submit a pull request to the authors of the original project to integrate your changes.
话虽如此,如果您的目标是处理分叉,您应该首先分叉代码,克隆分叉的代码,对其进行修改,然后将更改推送回分叉。完成后,您可以向原始项目的作者提交拉取请求以集成您的更改。
回答by vincent mathew
[DANGER] Dont attempt if you are working in a team
[危险] 如果您在团队中工作,请不要尝试
Try this.
尝试这个。
git push -f original master
Always saves the day...
总是节省一天...