【问题标题】:git rebase --onto causes conflict — why?git rebase --onto 导致冲突——为什么?
【发布时间】:2011-02-08 11:47:05
【问题描述】:

我正在尝试

git rebase --onto master myremote/master~21 myremote/master

从我的远程存储库添加最新的 21 个提交。

git 告诉我的是存在冲突——但这怎么可能?

据我了解,它只是将 21 次提交应用到我的 master 之上。怎么会有冲突?

感谢您的帮助!

顺便说一句,我这样做是因为我弄乱了我的 git-svn 存储库(远程),并且有 21 个提交我无法提交到颠覆。所以我正在尝试一个新的 git-svn 克隆,我在其中添加了这 21 个提交。

【问题讨论】:

    标签: git-svn conflict git-rebase


    【解决方案1】:

    如果发生冲突:

    • master 有不在myremote/master 中的提交。
    • 这些提交包括常见文件/更改,其中最后 21 个 myremote/master 提交。

    如果不知何故新的git-svn clone 与之前的 git-svn repo 具有不同的 SHA1,那么就没有密切的共同祖先,并且发生冲突的可能性要高得多。
    请参阅“How to identify conflicting commits by hash during git rebase?”了解变基期间的冲突说明。


    将本地 master 重置为 myremote/master 的一种方法是:

    git checkout -b tmp myremote/master  # local tmp branch from myremote/master HEAD.
    git merge -s ours master             # ignore completely master content
    git checkout master
    git merge tmp                        # fast-forward to tmp HEAD
    

    如果您在获取 myremote/master 之前没有对本地 master 进行任何更改,这应该可以工作。

    【讨论】:

    • 我不明白。为什么 master 中的任何提交都很重要?变基只是将当前分支(此处为 myremote/master)重置为 (此处为 master)。所以一切都应该应用在 master 之上,对吧?
    • 换句话说:有没有办法简单地应用这 21 个提交而无需 git 检查共同祖先和废话?
    • @Andy:关于变基期间的冲突,请参阅stackoverflow.com/questions/2118364/…。您的问题是:master/HEAD(在任何变基之前)的 SHA1 是否与myremote/master~22 相同?如果不是,那么共同祖先在master 的历史上更远,因此所有这些冲突。
    • 感谢您的回答。但据我了解 git rebase 上的文档,它不会检查 上的共同祖先。至少这是我想做的,我认为 rebase --onto 会做到这一点。
    • @Andy:在stackoverflow.com/questions/4911794/…中提出的我们的合并策略之后,我已经完成了我的答案,并采用了一种可能的方式来重置您的主人
    猜你喜欢
    • 2016-11-18
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    相关资源
    最近更新 更多