事情是这样的,我先是在一个git好了的目录连接了一个仓库创建了一个项目并发布到了那个仓库上,然后我又在idea中创建了一个更完整的项目,又连接到了这个git仓库中(俩项目名称相同),然后就想发布上去,结果add ,commit完成之后要push时,出现了这一幕
error: failed to push some refs to '我相关联的git仓库'
hint: Updates were rejected because the remote contains work that you do
! refs/heads/master:refs/heads/master [rejected] (fetch first)
Done
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.
根据它的提示我大概知道是冲突了因为之前提交的并不完整,我的本意是想用这个来覆盖之前的,于是我就想先pull下来解决冲突(事实上我pull下来不会影响我这个项目因为我在之前的目录下把不完整的项目给删除了,这个时候我的仓库其实是空的,但是会遗留下git自己的备份数据比如备份的版本log),结果我在pull的时候发生了如下一幕
warning: no common commits
remote: 对象计数中: 101, 完成.
remote: 压缩对象中: 100% (87/87), 完成.
remote: Total 101 (delta 43), reused 0 (delta 0)
Receiving objects: 100% (101/101), 17.27 KiB | 0 bytes/s, done.
Resolving deltas: 100% (43/43), done.
From 我相关联的git仓库
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories
说是拒绝让我合并不相关的历史
解决方案:
执行如下命令
git pull origin master --allow-unrelated-histories
然后就会解决冲突,如果说你的仓库项目跟你要上传的项目有冲突那你就解决冲突再push(前面说了我的仓库其实是空的只保留了git自己的log)
然后再push上去就成功了
Counting objects: 132, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (80/80), done.
Writing objects: 100% (132/132), 22.17 KiB | 0 bytes/s, done.
Total 132 (delta 56), reused 57 (delta 33)
remote: 处理 delta 中: 100% (56/56), 完成.
To 我关联的仓库 bdd1ac7..30c6958
Done
git新手做如上笔记