Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 为什么这个选择会导致合并冲突_Git_Cherry Pick_Git Cherry Pick - Fatal编程技术网

Git 为什么这个选择会导致合并冲突

Git 为什么这个选择会导致合并冲突,git,cherry-pick,git-cherry-pick,Git,Cherry Pick,Git Cherry Pick,编辑:我添加了一些我认为不必要的信息,但事实并非如此。 我有两个分支,A和B。在A中进行了三次提交后,更改了文件。c我想将它们挑选到B中,还有一个文件。h在A~1中更改 > 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

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

> 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
>git cherry选择一个~2
成功
>git cherry挑选一个~1
错误:无法应用81e0723。。。
提示:解决冲突后,标记更正的路径
提示:使用“git add”或“git rm”
提示:并使用“git commit”提交结果
>git状态
您当前正在提交81e0723。
未合并路径:
(使用“git add…”标记分辨率)
都已修改:some/unrelated/file.txt
都修改了:file.c

现在查看一些/无关的/FIL.TXT,它包含了文件的更改。这看起来像是git中的一个bug。因此,我现在将手动撤消对some/unrelated/file.txt的更改,并将它们添加到file.h中。

Cherry picking与按顺序应用一组修补程序没有什么不同(其好处是获得以前的提交消息)。这必然会产生新的blob——您可以通过注意到他提交的sha是不同的来验证这一点


当合并时间到来时,
git
现在认为它正在查看一个不同的历史,因为从技术上讲是这样的,因此合并冲突

可能是cherry pick正在更改一个在
B
的历史早期也已更改过的函数,因此
a~1
中的更改是针对那些看起来已经不同于
B
版本的行,git看不到cherry pick的更改在
B
中的何处应用


git为更改找到的上下文也可能在代码的其他地方有邪恶的孪生兄弟(比如,多行代码中只有独立的右括号),而其他的变化已经使代码中真正对应的原始内容与
A~1^
中的内容相去甚远,以至于在
B
中搜索上下文会找到其他内容。该手册建议,放弃cherry pick并使用git cherry pick-Xpatience重试可能足以避免这些问题,因为它们通常会花费不合理的时间来避免在支架的海洋中迷失方向

对于不相关的文件,它显示了什么变化?您能绘制一个提交图来描述您的情况吗?我有一种感觉,
rebase
也可以做得更简单。我现在已经解决了这个问题,今天晚些时候/明天会写一个详细的答案。@crunsher从来没有抽出时间来写这个?