gpt4 book ai didi

git - 为什么这个樱桃选择会导致 merge 冲突

转载 作者:太空狗 更新时间:2023-10-29 13:03:32 26 4
gpt4 key购买 nike

编辑:我添加了一些我认为不必要的信息,但事实并非如此。我有两个分支,A 和 B。在 A 中进行了三个更改 file.c 的提交之后,我想将它们挑选到 B 中,还有一个在 A~1 中更改的 file.h

> git cherry-pick A~2
Success
> git cherry-pick A~1
error: could not apply 81e0723...
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
> git status
You are currently cherry-picking commit 81e0723.
Unmerged paths:
(use "git add <file>..." to mark resolution)

both modified: some/unrelated/file.txt
both modified: file.c

现在,当查看 some/unrelated/file.txt 时,它包含对 file.h 中间某处的更改。所以这看起来像是 git 中的一个错误。所以我现在将手动撤消对 some/unrelated/file.txt 的更改并将它们添加到 file.h。

最佳答案

有可能 cherry-pick 正在更改一个函数,该函数在 B 的历史中早先也被更改过,因此 A~1 中的具体更改是针对行的看起来已经与 B 版本中的不同,git 看不到 B cherry-pick 更改适用的位置。

也有可能 git 为更改找到的上下文有邪恶的双胞胎在代码的其他地方等待(比如,多行除了独立的右括号什么都没有),并且其他更改已经将真正对应的原始代码放在代码中很远从它在 A~1^ 中的位置开始,在 B 中搜索上下文就找到了其他东西。该手册建议中止 cherry-pick 并使用 git cherry-pick -Xpatience 重试可能足以避免那些问题,因为它花费了通常不合理的时间来避免在海中迷路大括号。 Here's probably a good place to start if you want details on how that really works .

关于git - 为什么这个樱桃选择会导致 merge 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31002979/

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