允许在git rebase中合并不相关的历史记录 [英] Allow merging unrelated histories in git rebase
问题描述
当您想要保持合并提交时重新分配一个分支时,您传递 - preserve-merges
标志。当你在git中合并不相关的历史记录时,你需要传递 - allow-unrelated-history
标志。
如果您正在执行 git rebase --preserve-merges
,则当现有合并来自不相关的历史记录时,它将失败:
< blockquote>
fatal:拒绝合并不相关的历史记录
如果您尝试 git rebase --preserve-merges --allow-unrelated-history
失败:
error:unknown option' allow-unrelated-history'
是否有其他方法可以告诉rebase允许合并?
编辑:这是一个极小的复制: https://github.com/vossad01/rebase-unrelated-merge-reproduction
重现结帐 master
然后执行:
git reb ase --preserve-merges --onto origin / a-prime HEAD〜2
brute-force方法是强制一个通用根 - 因为你正在尝试重新绑定根,没有内容历史记录,所以做一个nonce空提交并告诉git这是你的历史记录的父代合并:
git rev-list --all --max-parents = 0 \
| awk'{print $ 0,empty}'empty =`:| git mktree | xargs git commit-tree` \
> .git / info / grafts
git rebase here
rm .git / info / grafts
When you want to rebase a branch keeping merge commits you pass the --preserve-merges
flag. When you are merging unrelated history in git you need to pass the --allow-unrelated-histories
flag.
If you are doing git rebase --preserve-merges
when an existing merge comes from an unrelated history, it fails:
fatal: refusing to merge unrelated histories
If you try git rebase --preserve-merges --allow-unrelated-histories
it fails with:
error: unknown option 'allow-unrelated-histories'
Is there some other way to tell rebase to allow the merge?
Edit: here is a minimal reproduction: https://github.com/vossad01/rebase-unrelated-merge-reproduction
To reproduce checkout master
then execute:
git rebase --preserve-merges --onto origin/a-prime HEAD~2
The brute-force method is to force a common root -- since you're trying to rebase roots, with no content history, make a nonce empty commit and tell git that's the parent of the histories you're merging:
git rev-list --all --max-parents=0 \
| awk '{print $0,empty}' empty=`:|git mktree|xargs git commit-tree` \
> .git/info/grafts
git rebase here
rm .git/info/grafts
这篇关于允许在git rebase中合并不相关的历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!