我非常喜欢
请看下面的例子:
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
如果我用git pull --no-rebase
替换git pull --rebase=preserve
,那么它会按预期工作(我只需要解决一次冲突),但是我必须查看日志中的所有合并提交。
我该如何让git "rebase"合并和解决冲突,以使其适合新的远程HEAD之上?
git pull --rebase=preserve
选项相当于git rebase --preserve-merges
,它指示重新基于保留合并。然而,显然那些合并的冲突解决在重新基础时不被考虑。 - Dan Fischer