gpt4 book ai didi

git - git rebase 是否比 git merge 产生更多的冲突?

转载 作者:IT王子 更新时间:2023-10-29 01:02:45 26 4
gpt4 key购买 nike

git rebase 真的比git merge 更容易发生冲突吗?我以前听说过,它在 this post 中被引用

I am speculating based on anecdata here, but I suspect the general anxiety around rebasing stems from two primary places:

  1. Due to the mechanics of git rebase, merge conflicts are more frequent and seemingly harder to deal with

作者没有详细说明这种说法,但我不是第一次听到这种说法。

我听过并理解这一点,因为 rebase 会逐个提交地重放,你最终会多次遇到同样的冲突,但我从未遇到过这种情况。也许 rerere 行为现在是 git rebase 中的默认行为?

我正在尝试在我的团队中提出 rebase 策略,但如果它是准确的,我想解决这个问题。

老实说,我预计会有相同数量的冲突,因为无论是 rebase 还是 merge ,两个分支中的更改最终都会发生冲突。换句话说,冲突不是末端分支收敛引起的,而是同一行的并行变化引起的

最佳答案

如果您有多个提交,您最终会与 rebase 发生更多冲突。这是因为当您 rebase 时,您必须解决每次提交的冲突。这意味着,如果您尝试 rebase 一个比您的 master 提前 5 次提交的分支,并且您在这 5 次提交中的第一次提交中引入了 merge 冲突,您将必须在以下每个提交中解决该冲突。

Rebase 通常应该可以解决上述问题。另外值得一提的是,如果您想压缩到单个提交,有一个比 rebase 更简单的策略。

假设您有 5 个提交要 merge 到 master 中,但这只是一个可以在一个提交中使用描述性消息轻松描述的功能。

git fetch
git merge origin/master
git reset --soft origin/master
git commit

如果你只想要一次提交,这会更容易,并且可以完成与 rebase 相同的事情。

关于git - git rebase 是否比 git merge 产生更多的冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34298273/

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