git 为什么这个樱桃选择会导致合并冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31002979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does this cherry pick result in a merge conflict
提问by crunsher
Edit: I added some Information I thought to be unnecessary, but is not. I have two branches, A and B. After making three commits in A that changes file.c I want to cherry-pick them into B, there is also a file.h which was changed in A~1
编辑:我添加了一些我认为不必要的信息,但事实并非如此。我有两个分支,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
Now when looking at some/unrelated/file.txt it contains the changes to file.h somewhere right in the middle. So this looks like a bug in git. So I will now undo the changes some/unrelated/file.txt manually and add them to file.h.
现在,当查看 some/unrelated/file.txt 时,它包含对 file.h 的更改,就在中间的某处。所以这看起来像是 git 中的一个错误。所以我现在将手动撤消 some/unrelated/file.txt 的更改并将它们添加到 file.h。
回答by jthill
It's possible the cherry-pick is changing a function that had also been changed earlier in B
's history, so the changes specifically in A~1
are to lines that already looked different from what's in the B
version and git can't see where in B
the cherry-pick's changes apply.
有可能cherry-pick 正在改变一个在B
历史上也被更改过的函数,所以特别A~1
是更改已经与B
版本中的内容看起来不同的行,git 看不到B
cherry-pick 中的哪个位置更改适用。
It's also possible that the context git finds for the changes has evil twins lying in wait elsewhere in the code (say, multiple lines with nothing but standalone closing braces), and other changes have put the real corresponding original in your code far enough from where it was in A~1^
that the hunt for the context in B
finds something else instead. The manual suggests aborting the cherry-pick and retrying with git cherry-pick -Xpatience
might be enough to avoid trouble with those, that spends an ordinarily-unreasonable amount of time trying to avoid getting lost in a sea of braces. Here's probably a good place to start if you want details on how that really works.
也有可能 git 为更改找到的上下文在代码中的其他地方等待着邪恶的双胞胎(例如,多行只有独立的右大括号),而其他更改已将真正对应的原始代码放置在代码中的位置离那里足够远正是在A~1^
寻找上下文的过程中B
找到了其他东西。该手册建议中止挑选并重试git cherry-pick -Xpatience
可能足以避免那些麻烦,这花费了通常不合理的时间来避免迷失在大括号的海洋中。如果您想了解其真正工作原理的详细信息,这可能是一个很好的起点。
回答by Murphy Danger
Cherry picking is no different than applying a set of patches in order (with the benefit of getting previous commit messages). This necessarily results in new blobs--which you can verify by noting that he commit sha's are different.
樱桃采摘与按顺序应用一组补丁没有什么不同(这样做的好处是可以获得以前的提交消息)。这必然会导致新的 blob——您可以通过注意到他提交的 sha 是不同的来验证这一点。
When merge time comes, git
now thinks it's looking at a different history, because technically it is, and hence a merge conflict.
当合并时间到来时,git
现在认为它正在查看不同的历史,因为从技术上讲它是,因此合并冲突。