文章内容
2018/4/11 13:59:22,作 者: 黄兵
Updates were rejected because the remote contains work that you do
最近在提交代码的时候,报如下错误:
Admin@Administrator MINGW64 /d/htdocs/work.local.com/www-local-com (develop)
$ git merge lernado
Updating 764de39..7717317
Fast-forward
controllers/ListsController.php | 1 -
1 file changed, 1 deletion(-)
Admin@Administrator MINGW64 /d/htdocs/work.local.com/www-local-com(develop)
$ git push origin develop
To git@git.develop.com:admin.site/www-develop-com.git
! [rejected] develop-> develop (fetch first)
error: failed to push some refs to 'git@git.develop.com:admin.site/www-develop-com.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.
Admin@Administrator MINGW64 /d/htdocs/work.local.com/www-local-com (develop)
我觉得你本地的开发分支develop
可能不是最新的,就是和远程的开发分支develop
不是同一版本。这种问题我遇到过,一般你在执行git push origin 分支
之前最好执行一下git pull origin 分支
,保证本地和远程为同一版本在更新就没问题了。你执行如下命令之后再试试看
#先执行
git pull origin develop
#在执行
git push origin develop
但是有报错了,具体如下:
F:\WebSite Source Code\SMS_ReciveProject>git push -u origin master
Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa':
To github.com:sycct/sms_receive.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:sycct/sms_receive.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
导致原因:
是因为远程repository和我本地的repository冲突导致的,而我在创建版本库后,在github的版本库页面点击了创建README.md文件的按钮创建了说明文档,但是却没有pull到本地。这样就产生了版本冲突的问题。
有如下几种解决方法:
1.使用强制push的方法:
$ git push -u origin master -f
这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
2.push前先将远程repository修改pull下来
$ git pull origin master
$ git push -u origin master
3.若不想merge远程和本地修改,可以先创建新的分支:
$ git branch [name]
然后push
$ git push -u origin [name]
评论列表