gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:54:21 28 4
gpt4 key购买 nike

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

试试看下面的例子:

# 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 --rebase=preserve 替换为 git pull --no-rebase 那么它会按预期工作(我只需要解决一次冲突) ,但我必须在我的日志中查看所有这些 merge 提交。

我怎样才能让 git “ rebase ”解决 merge 和冲突,使其适合新远程 HEAD 的顶部?

最佳答案

我发现 Git“rerere”功能解决了我的问题。

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

将此添加到我的 .gitconfig

[rerere]
enabled = true

解决了我的问题。

关于GIT:为什么我在使用 rebase 时需要解决我的 merge 冲突两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28415276/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com