69

我从我的分支的 gerrit 评论中挑选了樱桃。在 gerrit 代码审查中,我有两个补丁集,我之前挑选了一个补丁,所以现在我想做第二个补丁集,但是有冲突,我如何强制 git 接受所有更改?谢谢!

4

4 回答 4

130

您可以告诉它始终喜欢您正在挑选的提交的更改:

git cherry-pick commitish --strategy-option theirs

commitish可以是提交的 SHA-1 哈希,也可以是branch-name该分支的最新提交,branch-name~1之前的提交等。

如果你想做相反的事情,请使用:

git cherry-pick commitish --strategy-option ours

的简写--strategy-option-X大写的X)。

PS:什么是 commit-ish,tree-ish?

于 2015-09-08T23:00:45.440 回答
13

git cherry-pick -X theirs <commit-hash-you-want-to-force-cherry-pick-from>

我通常的工作流程如下:

假设我在主人身上并且我刚刚做出了承诺。

  1. 我抓住了那个提交的提交哈希。
  2. 然后结帐到我想要提交的分支。
  3. 然后运行上面的命令,例如git cherry-pick -X theirs 5cf3412
于 2018-02-09T18:59:16.287 回答
6

如果您已经处于冲突状态,只需执行

# add only conflicting files here
git checkout --theirs path/to/file
git add path/to/file
git cherry-pick --continue
于 2017-12-19T04:30:48.110 回答
0

你可以用这样的东西蛮力它:

git show cb1e6a:path/to/filename > path/to/filename
git add path/to/filename
git commit

但我确信有更简单的方法。

于 2015-04-23T08:12:29.877 回答