尝试将代码从本地推送到远程时Github错误

时间:2016-03-08 23:23:30

标签: git github

我尝试将代码从本地推送到远程时出现以下错误:

"To https://github.com/rishabhsrana/webdev.git
 ! [rejected]        master -> master (fetch first)
 error: failed to push some refs to '     https://github.com/rishabhsrana/webdev.git'
 hint: Updates were rejected because the remote contains work that you do
 hint: not have locally. This is usually caused by another repository     pushing
 hint: to the same ref. You may want to first integrate the remote changes
 hint: (e.g., 'git pull ...') before pushing again.
 hint: See the 'Note about fast-forwards' in 'git push --help' for details."

有人可以帮我解决这个问题,因为我不知道如何处理。

仅供参考,我尝试使用以下命令在几分钟后清除我的提交历史记录(虽然它已在cmd提示符下成功实现,但我的历史记录在我的github页面上仍然完好无损):

git init
git remote add origin git@github.com:user/repo
now commit your current version of code

git add *
git commit -am 'message'
and finally force the update to GitHub:

git push -f origin master

4 个答案:

答案 0 :(得分:0)

您遇到的错误是因为您正在尝试推送本地更改"背后"遥控器上的现有更改。

这里的解决方案是提交您的本地工作(您已完成)然后从远程执行。这将导致合并(并且可能是合并冲突)。如果需要,解决合并冲突,提交这些合并更改。现在,一切都应该准备好迎接新的"推动" :)

答案 1 :(得分:0)

尝试从git pull origin master

开始

错误消息显示远程主服务器上有您本地没有的更改。为了不消除这些变化,你必须在推动之前拉动。

答案 2 :(得分:0)

在推送更改之前,您应该从原点拉取以获取最新代码。

git pull origin master

答案 3 :(得分:0)

感谢您的回复如此之快。

我已经尝试过===> “git pull origin master”并得到以下回复:

"C:\Users\risha_000\CS5610Code>git pull origin master
 From ssh://webdevelopment-ranarishabhsingh.rhcloud.com/~/git/webdevelopment
 * branch            master     -> FETCH_HEAD
 Already up-to-date."

我也阅读了“git-push手册页”,但坦率地说,我无法理解其中的大部分内容。

请建议做什么,感谢您的耐心等待,请相信我对这些东西的经验不好,但我正试图熟悉它。