Git提交代码及异常处理方法
1.开始步骤
- 第一步:首先在gitee.com上创建一个项目,与你本地项目同名
- 第二步:在git bash 下操作
① git init 初始化本地仓库
② git add . 将当前文件加入到仓库
③ git commit -m ‘first commit’ 第一次提交项目文件
④ git remote add origin https://gitee.com/null_948_8938/ayiol_auth.git 关联远程仓库,蓝色为git项目URL
⑤ git push -u origin master 推送远程仓库
2.异常
error: failed to push some refs to 'https://gitee.com/null_948_8938/ayiol_auth.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.
方法:报错因为远程仓库与本地仓库文件不一致,使用git pull拉下远程代码到本地
git pull
warning: no common commits remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From https://gitee.com/null_948_8938/ayiol_auth * [new branch] master -> origin/master There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master
原因:报错原因是没有指定本地master和远程origin/master的连接,
执行git branch –set-upstream master origin/master,设置链接
git branch --set-upstream master origin/master
fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.
原因:
再次执行:git pull origin master
fatal: refusing to merge unrelated histories 拒绝合并不相关的历史
原因:
报错原因是本地仓库与远程仓库不同 解决方案: git添加一句代码,这句代码是在git2.9.2版本发生的,最新版本需要添加 --allow-unrelated-histories,此代码为忽略不相关历史文件 即:git pull origin master --allow-unrelated-histories 重新git push origin master ,不在报错,推送完成
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/118701.html