Git Cherry-Pick 和冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19830464/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:15:32  来源:igfitidea点击:

Git Cherry-Pick and Conflicts

gitcherry-pickgit-cherry-pick

提问by Abhinav

There are two different git branches. In one the development is going in (Branch1).

有两个不同的 git 分支。其中一个开发正在进行(Branch1)。

In other branch some PoC work is going on (Branch2). Now, I want to cherry-pick the changes from Branch1 to Branch2, so that Branch2 is up to date.

在其他分支中,一些 PoC 工作正在进行(Branch2)。现在,我想挑选从 Branch1 到 Branch2 的更改,以便 Branch2 是最新的。

Now, after cherry-picking 4 or 5 changes, I am getting some merge conflict and I am unable to proceed with further cherry-picks.

现在,在挑选 4 或 5 个更改之后,我遇到了一些合并冲突,并且无法继续进行进一步的挑选。

Do, I need to resolve all the conflicts before proceeding to next cherry -pick or Can I somehow postpone the conflict resolution till I cherry-pick all the changes (and resolve all conflicts together)?

是否,我需要在继续下一个cherry-pick之前解决所有冲突,或者我可以以某种方式推迟冲突解决,直到我cherry-pick所有更改(并一起解决所有冲突)?

Further, is it suggested to do cherry-pick or branch merge in this case?

此外,在这种情况下是否建议进行cherry-pick或分支合并?

采纳答案by sleske

Do, I need to resolve all the conflicts before proceeding to next cherry -pick

做,我需要在继续下一个cherry-pick之前解决所有冲突

Yes, at least with the standard git setup. You cannot cherry-pick while there are conflicts.

是的,至少使用标准的 git 设置。当有冲突时,你不能挑剔。

Furthermore, in general conflicts get harder to resolve the more you have, so it's generally better to resolve them one by one.

此外,通常冲突越多,解决起来就越困难,因此通常最好一一解决。

That said, you cancherry-pick multiple commits at once, which would do what you are asking for. See e.g. How to cherry-pick multiple commits. This is useful if for example some commits undo earlier commits. Then you'd want to cherry-pick all in one go, so you don't have to resolve conflicts for changes that are undone by later commits.

也就是说,您可以一次挑选多个提交,这将满足您的要求。参见例如如何挑选多个提交。例如,如果某些提交撤消了较早的提交,这将很有用。然后,您希望一次性挑选所有内容,这样您就不必解决因以后提交而撤消的更改的冲突。

Further, is it suggested to do cherry-pick or branch merge in this case?

此外,在这种情况下是否建议进行cherry-pick或分支合并?

Generally, if you want to keep a feature branch up to date with main development, you just merge master -> feature branch. The main advantage is that a later merge feature branch -> master will be much less painful.

一般来说,如果你想让一个特性分支与主开发保持同步,你只需合并 master -> 特性分支。主要优点是以后的合并功能分支 -> master 会少很多痛苦。

Cherry-picking is only useful if you must exclude some changes in master from your feature branch. Still, this will be painful so I'd try to avoid it.

Cherry-picking 仅在您必须从功能分支中排除 master 中的某些更改时才有用。不过,这会很痛苦,所以我会尽量避免它。

回答by Claudio

Before proceeding:

在继续之前:

  • Install a proper mergetool. On Linux, I strongly suggest you to use meld:

    sudo apt-get install meld
    
  • Configure your mergetool:

    git config --global merge.tool meld
    
  • 安装合适的合并工具。在 Linux 上,我强烈建议你使用 meld:

    sudo apt-get install meld
    
  • 配置您的合并工具:

    git config --global merge.tool meld
    

Then, iterate in the following way:

然后,按以下方式迭代:

git cherry-pick ....
git mergetool
git cherry-pick --continue

回答by jeremie

Also, to complete what @claudio said, when cherry-picking you can also use a merging strategy.

另外,为了完成@claudio 所说的,在挑选樱桃时,您还可以使用合并策略

So you could something like this git cherry-pick --strategy=recursive -X theirs commitor git cherry-pick --strategy=recursive -X ours commit

所以你可以像这样git cherry-pick --strategy=recursive -X theirs commitgit cherry-pick --strategy=recursive -X ours commit