记录程序猿开发过程中已经遇到的各种坑,再记录解决方法 / Record the various pits that have been encountered during the development process, and then record the solution.
2
stars
0
forks
source link
git无法pull仓库refusing to merge unrelated histories #7
Open
jingxinxin opened 6 years ago
当大量修改本地,或者完全两个不同的项目覆盖的时候,比如本地项目完全覆盖远端的项目 我只需要执行
git push --force
就会强制push当前的项目,包括log的记录也会被强制覆盖当我们在另一个地址pull,因为两个仓库不同,发现refusing to merge unrelated histories,无法合并 因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories 假如我们的源是origin,分支是master,那么我们 需要这样写
git pull origin master --allow-unrelated-histories
但是有个问题是会发生冲突,如果你需要保留logs记录,你可以解决冲突,如果你完全不需要之前的项目记录,只需要git fetch --all //只是下载代码到本地,不进行合并操作
git reset --hard origin/master //把HEAD指向最新下载的版本