git subtree 错误“致命:拒绝合并不相关的历史”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39281079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git subtree error "fatal: refusing to merge unrelated histories"
提问by Matthijs
I'm trying to figure out how 'git subtree' works. I've followed all directions on this page, but I always get an error trying to merge the subtree project in my own repo ('Step 2'): fatal: refusing to merge unrelated histories
.
我试图弄清楚“git subtree”是如何工作的。我跟着上四面八方此页面,但我总是想在我自己的回购协议(“第二步”)合并子树项目的错误:fatal: refusing to merge unrelated histories
。
I've read this post, and when I use the --allow-unrelated-histories
option, it seems to work fine. However, I'm not sure whether I should use this...My impression is that the whole point of subtrees is to have unrelated histories within one repository, so it feels strange to have to add the option. Should I add it nevertheless, or am I doing something wrong?
我已经阅读了这篇文章,当我使用该--allow-unrelated-histories
选项时,它似乎工作正常。但是,我不确定我是否应该使用它...我的印象是子树的全部意义在于在一个存储库中具有不相关的历史记录,因此必须添加该选项感觉很奇怪。我应该添加它,还是我做错了什么?
I'm using git v2.9.3 on osx 10.11.6
我在 osx 10.11.6 上使用 git v2.9.3
采纳答案by daurnimator
This was a bug in git, it was fixed in https://github.com/git/git/commit/0f12c7d4d175bb0566208213b1b340b6794f305c
这是 git 中的一个错误,已在https://github.com/git/git/commit/0f12c7d4d175bb0566208213b1b340b6794f305c中修复
回答by PencilBow
If the subtree was added using --squash
, you need to also use --squash
when you pull
如果子树是使用添加的--squash
,则--squash
在拉取时还需要使用
git subtree pull --prefix=<folder-goes-here> <remote-goes-here> <branch-goes-here> --squash
git subtree pull --prefix=<folder-goes-here> <remote-goes-here> <branch-goes-here> --squash
回答by Cyrus
I've been struggling with this for a while and think I found the solution.
我已经为此苦苦挣扎了一段时间,并认为我找到了解决方案。
I'm pretty new to git so forgive me if I use the wrong names for things.
我对 git 很陌生,所以如果我对事物使用错误的名称,请原谅我。
The problem may have come from you using the --squash
option when you ran the git subtree add command.
问题可能来自您--squash
在运行 git subtree add 命令时使用该选项。
Try removing the subtree (remove the remote repository and delete all the local files, commit, and push). Then redo the subtree add without the --squash
option.
尝试删除子树(删除远程存储库并删除所有本地文件、提交和推送)。然后在没有--squash
选项的情况下重做子树添加。
I then jumped over to my subtree repository, made some changes, committed and pushed, then hopped back to my main superproject repository and did a git subtree pull. It gave me some error about the working tree having modifications. To get around that I did a git checkout master, then a git push, then tried the subtree pull again. It worked.
然后我跳转到我的子树存储库,进行一些更改,提交和推送,然后跳回我的主要超级项目存储库并执行 git subtree pull。它给了我一些关于修改工作树的错误。为了解决这个问题,我做了一个 git checkout master,然后是 git push,然后再次尝试了 subtree pull。有效。
Hope that helps.
希望有帮助。
回答by granadaCoder
I am not expert.
我不是专家。
But I found something. I was originally trying just a normal pull. But I found this specific subtree pull.
但我发现了一些东西。我最初只是尝试正常拉动。但我发现了这个特定的子树拉。
git subtree pull --prefix myPrefixname https://github.com/subTreeRepo.git master --squash
where master is the branch name of course
其中 master 是当然的分支名称
(from
(从
https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree/
https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree/
)
)