Git pull失败之refusing to merge unrelated histories

来源:互联网 发布:浏览器源码 编辑:程序博客网 时间:2024/05/29 07:19

git pull 失败 ,提示:fatal: refusing to merge unrelated histories

这是因为远程仓库origin上的分支master和本地分支master被Git认为是不同的仓库,所以不能直接合并。

参考http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories。

解决方案:添加--allow-unrelated-histories

假如我们的远程仓库是origin,分支是master,那么我们 需要这样写git pull origin master ----allow-unrelated-histories

附:push和pull命令格式:

git push <远程主机名> <本地分支名>[:<远程分支名>]    e.g., git push oschina master, 省略远程分支名,代表推送到有追踪关系的远程分支(一般为同名)
git pull <远程主机名> <远程分支>:<本地分支>       e.g., git pull oschina master,省略远程分支名,同理

另外,我发现Pull命令不会删除本地工作区内的“其它文件夹”(即远程仓库没有的文件夹),文件还没试过。

附上经典Git原理图(摘自廖学峰的git教程):工作区就是直接包含本地代码文件的文件夹,stage(或称index)是暂存区(暂存add进来的修改过的代码),commit之后合并到本地仓库的分支(如master)。stage区和本地仓库均存储在.git文件夹内。

git-repo

阅读全文
0 0