Git无法提取与错误无关的历史记录

时间:2019-01-05 16:43:26

标签: android git

所以我有一个android studio项目,正在使用git在笔记本电脑和计算机之间进行同步。每次我尝试推时,一个推而另一个推时,都会出现错误,拒绝合并无关的历史记录

我尝试使用--allow-unrelated-histories,但这会导致大量合并冲突。

我需要能够在两者之间进行同步,因为我的计算机支持模拟器,并且笔记本电脑是便携式的。

2 个答案:

答案 0 :(得分:1)

发生这种情况是因为您的存储库是独立初始化的。

您应该仅在一个位置创建存储库,然后将其克隆到另一位置。

如果另一个存储库已经存在,并且您有一些不想丢失的更改,则可以执行以下操作:

(from location2, commit all uncommitted changes first!)
git fetch location1
git branch save_location2
git reset --hard origin/location1

因此,您切换到从location1开始的历史记录,并且不会丢失从location2开始的历史记录,并且可以从那里查找内容。

在某些特殊情况下,您应该使用--allow-unrelated-histories,但我敢肯定这不是您的情况。

答案 1 :(得分:0)

我有同样的问题。试试这个:

git pull origin master --allow-unrelated-histories 

git push origin master

参考:-Github unrelated histories issue