GIT:为什么我在使用rebase时需要解决两次合并冲突?

All*_*lan 8 git git-branch

我真的很喜欢这个git pull --rebase选项,但是当它与合并冲突结合使用时,我最终解决了两次冲突.我试图使用git pull --rebase=preserve哪个应该考虑合并.

试试看下面的例子:

# do a new clone "a"
$ mkdir origin && cd origin && git init --bare --shared && cd ..
$ git clone ./origin a && cd a

# Add, commit, push
a (master) $ echo "foo" > foo && git add foo && git commit -m "foo"
a (master) $ git push origin master

# Create branch "b"
a (master) $ git branch b

# change foo and push
a (master) $ echo "// eof " >> foo && git ci -am "eof - master"
a (master) $ git push origin master

# checkout branch "b", change and push
a (master) $ git checkout b
a (b) $ echo "// EOF " >> foo && git ci -am "EOF b" && git push origin b

# back to master
a (b) $ git checkout master

# merge
a (master) $ git merge b # conflict as expected
a (master) $ git diff
diff --cc foo
index e10b853,1d3cc50..0000000
--- a/foo
+++ b/foo
@@@ -1,2 -1,2 +1,6 @@@
  foo
++<<<<<<< HEAD
 +// eof
++=======
+ // EOF
++>>>>>>> b

# Now, resolve the conflict
a (master|MERGING) $ echo "foo" > foo && echo "// eof" >> foo && git add foo
a (master|MERGING) $ git commit

# In the mean while somewhere else. ############################################
a (master) $ cd ..  && git clone ./origin other && cd other/
other (master) $ echo "bar" > bar && git add bar && git ci -am "bar" && git push # OK

# Back to us ###################################################################
other (master) $ cd ../a
a (master) $ git push # will fail...

# I now do a rebase preserve as I want to rebase my merge commit to the top of master
a (master) $ git pull --rebase=preserve # This command does not do a very good job...
a (master|REBASE-i 1/1) $ git diff
diff --cc foo
index e10b853,1d3cc50..0000000
--- a/foo
+++ b/foo
@@@ -1,2 -1,2 +1,6 @@@
  foo
++<<<<<<< HEAD
 +// eof
++=======
+ // EOF
++>>>>>>> 3cd5d3ac5b870c613233f0a9f1a81df5691ccc7c
Run Code Online (Sandbox Code Playgroud)

如果我替换git pull --rebase=preservegit pull --no-rebase然后它按预期工作(我只需要解决冲突一次),但后来我必须在我的日志中查看所有这些合并提交.

我如何让git"重新组合"合并和冲突解决方案,使其适合新的远程HEAD?

All*_*lan 5

我发现Git"rerere"功能解决了我的问题.

记录在:git rerere --helphttp://git-scm.com/docs/git-rerere

将此添加到我的 .gitconfig

[rerere]
    enabled = true
Run Code Online (Sandbox Code Playgroud)

解决了我的问题.