强制 git 接受cherry-pick 的更改

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

force git to accept cherry-pick's changes

gitgit-cherry-pick

提问by Jiang

I did cherry-pick from a gerrit review in my branch. In gerrit code review, I have two patch sets and I cherry-picked patch one before, so now I want to do the second patch set, but there are conflicts, how can I force git to accept all changes? Thanks!

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

回答by CodeManX

You can tell it to always prefer the changes of the commit you are cherry-picking:

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

git cherry-pick commitish --strategy-option theirs

commitishcan be a SHA-1 hash of a commit, or a branch-namefor the lastest commit of that branch, branch-name~1for the commit before that etc.

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

If you want to do the reverse, use:

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

git cherry-pick commitish --strategy-option ours

The shorthand for --strategy-optionis -X(uppercase X).

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

回答by tallamjr

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

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

My usual workflow is as follows:

我通常的工作流程如下:

Assuming I'm on the masterand I have just made a commit.

假设我在master 上并且我刚刚提交了。

  1. I grab the commit hash of that commit.
  2. Then checkout on to the branch I want to have such commit.
  3. Then run the command above, e.g. git cherry-pick -X theirs 5cf3412
  1. 我获取该提交的提交哈希。
  2. 然后结帐到我想要进行此类提交的分支。
  3. 然后运行上面的命令,例如 git cherry-pick -X theirs 5cf3412

回答by geek-merlin

If you are already in conflict state, simply do

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

# add only conflicting files here
git checkout --theirs path/to/file
git add path/to/file
git cherry-pick --continue

回答by Jason B

you could brute force it with something like this:

你可以用这样的东西来暴力破解它:

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

but I'm sure there's an easier way.

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