强制 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
force git to accept cherry-pick's changes
提问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
commitish
can be a SHA-1 hash of a commit, or a branch-name
for the lastest commit of that branch, branch-name~1
for 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-option
is -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 上并且我刚刚提交了。
- I grab the commit hash of that commit.
- Then checkout on to the branch I want to have such commit.
- Then run the command above, e.g.
git cherry-pick -X theirs 5cf3412
- 我获取该提交的提交哈希。
- 然后结帐到我想要进行此类提交的分支。
- 然后运行上面的命令,例如
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.
但我相信有更简单的方法。