第一次上传代码时出现以下错误:
D:\java_projects\test>git push origin master
To https://git.oschina.net/qingke3/tom.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.oschina.net/qingke3/tom.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.
原因:远程代码库有某些文件本地代码库中不存在,会有冲突的隐患。
解决方法:需要先执行git pull的操作,把远程代码先拿下来,如下:
D:\java_projects\test>git pull origin master
From https://git.oschina.net/qingke3/tom
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
这时还是有错误,这是因为git拒绝合并无关的历史纪录,解决方法是在git pull时加上–allow-unrelated-histories,如下:
git pull origin master --allow-unrelated-histories
最后在push即可
本文介绍了在使用Git过程中遇到的推送代码失败问题及其解决步骤。当本地分支落后于远程分支时,推送会遭到拒绝。文章提供了如何通过拉取最新代码并解决历史记录不相关的问题来完成代码同步。

3228

被折叠的 条评论
为什么被折叠?



