【问题标题】:git rebase strange confliction, there are unexcpected contendgit rebase 奇怪冲突,有意外内容
【发布时间】:2012-06-13 04:09:41
【问题描述】:

我有两个分支:master,joy。 有一个名为'hello'的文件,我输入命令'git rebase joy',有冲突,冲突内容很奇怪。

以下是详细步骤

  • 1.

git 结帐大师

猫你好

显示 ==>

 Hello world
  • 2.

git checkout 欢乐

猫你好

显示 ==>

Hello world
one line
two line
  • 3.

git 结帐大师

git rebase joy ==>

First, rewinding head to replay your work on top of it...
Applying: cherry-pick
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging hello
CONFLICT (content): Merge conflict in hello
Failed to merge in the changes.
Patch failed at 0001 cherry-pick

猫你好==>

Hello world
<<<<<<< HEAD
one line
two line
=======
add one line
add 2nd line
>>>>>>> cherry- pick

但是我希望找到的是没有冲突,内容是

Hello world
one line
two line
  • 5.

我下面的版本树经过研究比较复杂

* <b04ea3b> 2012-06-09 [yaoyangyong]  (HEAD, joy) test rebase
* <5b595d6> 2012-06-09 [yaoyangyong]  joy clear hello
| * <eeba7d9> 2012-06-09 [yaoyangyong]  (master) clean hello
| *   <1dbc3b8> 2012-06-09 [yaoyangyong]  merge confilct
| |\  
| |/  
|/|   
| * <3cb9d88> 2012-06-09 [yaoyangyong]  modify master 1st line
* | <b1724ad> 2012-06-09 [yaoyangyong]  test merge
| *   <89a692f> 2012-06-09 [yaoyangyong]  merge from joy
| |\  
| |/  
|/|   
* | <dc96da9> 2012-06-09 [yaoyangyong]  modify second line
| *   <816f575> 2012-06-08 [yaoyangyong]  joy
| |\  
| |/  
|/|   
* | <93b5982> 2012-06-08 [yaoyangyong]  3line
| * <4400260> 2012-06-08 [yaoyangyong]  cherry-pick
* | <233d6f2> 2012-06-08 [yaoyangyong]  2nd line comment
* | <60d6edc> 2012-06-08 [yaoyangyong]  modify hello,add one line
|/  
:
* <b04ea3b> 2012-06-09 [yaoyangyong]  (HEAD, joy) test rebase
* <5b595d6> 2012-06-09 [yaoyangyong]  joy clear hello
| * <eeba7d9> 2012-06-09 [yaoyangyong]  (master) clean hello
| *   <1dbc3b8> 2012-06-09 [yaoyangyong]  merge confilct
| |\  
| |/  
|/|   
| * <3cb9d88> 2012-06-09 [yaoyangyong]  modify master 1st line
* | <b1724ad> 2012-06-09 [yaoyangyong]  test merge
| *   <89a692f> 2012-06-09 [yaoyangyong]  merge from joy
| |\  
| |/  
|/|   
* | <dc96da9> 2012-06-09 [yaoyangyong]  modify second line
| *   <816f575> 2012-06-08 [yaoyangyong]  joy
| |\  
| |/  
|/|   
* | <93b5982> 2012-06-08 [yaoyangyong]  3line
| * <4400260> 2012-06-08 [yaoyangyong]  cherry-pick
* | <233d6f2> 2012-06-08 [yaoyangyong]  2nd line comment
* | <60d6edc> 2012-06-08 [yaoyangyong]  modify hello,add one line
|/  
* <aeae413> 2012-06-08 [yaoyangyong]  add hello file
  • 6

作为比较,我重新创建了一个干净的文件夹,它的版本树非常简单,如下所示,然后我做rebase,它是成功的。

* <0d63388> 2012-06-09 [yaoyangyong]  (joy) add two lines
* <1f9d2f4> 2012-06-09 [yaoyangyong]  (HEAD, master) add hello file

【问题讨论】:

  • 您可能需要将配置变量 merge.conflictstyle 设置为 diff3,因为这将向您显示来自合并的公共基础的大块,这可能会使“冲突”在哪里更清楚来自。

标签: git conflict rebase


【解决方案1】:

这对我来说有点奇怪。通常,您永远不想变基 master。变基通常在私有分支上完成,以便在合并时执行快进合并。使用 rebase -i 进行变基还可以让您有机会在将提交合并到公共分支(主分支)之前压缩和修复提交。

我想看看这里以了解什么是变基和做什么:http://git-scm.com/book/en/Git-Branching-Rebasing

使用您的示例,我希望是这样的:

1.

git checkout master
cat hello

显示 ==>

Hello World

2.

git checkout joy
cat hello

显示 ==>

Hello World
one line
two line

3.

此时有两个commit,第一个commit同时存在于master和joy中,第二个commit只存在于joy中。现在我们可以合并,但我们要确保快乐的提交将干净地应用(避免合并提交)。为了做到这一点,我们将快乐重新建立在主人身上。

仍在欢乐分支上运行

git rebase master

或者,您可以使用交互模式,让您可以压缩、修复、重新排序等

git rebase -i master

4.

现在我们的joy分支已经按照我们想要的方式查看并重新基于master,我们可以切换到master并进行合并以获得漂亮的历史记录。

git checkout master
git merge joy

5。重要

当您执行变基时,这些提交的 SHA-1 标识符将发生变化。任何基于这些提交工作的人最终都会遇到很多麻烦,因为他们的提交的父级不再存在。这就是为什么你永远不会变基公共分支的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 2017-09-29
    相关资源
    最近更新 更多