记一次Git提交报错的问题

通常代码版本控制的步骤是:

  • 在代码版本控制平台新建一个仓库
  • clone远程仓库到本地
  • 开始编码,然后是一系列add,commit,push

    我的步骤是:

  • 在远程代码版本管理平台新建一个仓库
  • 在本地新建一个项目
  • 通过git remote add添加远程仓库
  • 然后add, commit, push
    但是commit时就报错了:
error: failed to push some refs to ....
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.

这说明此时两个仓库并没有建立关联,两个仓库的代码没有同步。
按照提示使用git pull拉取远程代码并合并又出现如下错误:

 refusing to merge unrelated histories

意思是两个仓库的历史记录不相关。

最终解决方案:

允许不相关的历史:

git pull origin master --allow-unrelated-histories

然后再push.

猜你喜欢

转载自www.cnblogs.com/wotoufahaiduo/p/11669074.html
今日推荐