用 git 挑选有冲突的樱桃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16069668/
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
cherry-picking with git with a conflict
提问by szabgab
I have two branches Z with some changed and M with some conflicting changes. I'd like to merge the first change on Z into M. When I try to see which changes are still out there. (There are actually a few more changes but this already shows the problem)
我有两个分支 Z 有一些变化,M 有一些相互冲突的变化。我想将 Z 上的第一个更改合并到 M 中。当我尝试查看哪些更改仍然存在时。(实际上还有一些变化,但这已经表明了问题)
$ git checkout M
$ git cherry M Z
+ 153c2f840f2192382be1fc435ceb069f0814d7ff
+ 4a7979d5dd526245b51769db21acf4c286825036
$ git cherry-pick 153c2f840f2192382be1fc435ceb069f0814d7ff
error: could not apply 153c2f8... add Z
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'
? (M|CHERRY-PICKING) $ git st
# On branch M
# Unmerged paths:
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: README.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
? (M|CHERRY-PICKING) $ vim README.txt
I fixed the conflict here
我在这里解决了冲突
? (M|CHERRY-PICKING) $ git add README.txt
? (M|CHERRY-PICKING) $ git ci -m'cherry picked'
[M dc5de35] cherry picked
1 file changed, 1 insertion(+), 1 deletion(-)
? (M) $ git cherry M Z
+ 153c2f840f2192382be1fc435ceb069f0814d7ff
+ 4a7979d5dd526245b51769db21acf4c286825036
So after I committed the change it still thinks that neither changes were cherry-picked I was expecting:
因此,在我提交更改后,它仍然认为这两个更改都不是我所期待的:
- 153c2f840f2192382be1fc435ceb069f0814d7ff
+ 4a7979d5dd526245b51769db21acf4c286825036
How am I going to know a week from now that I already merged 153c2f ? How can I do the cherry-picking in a way that it will know about that merge?
我怎么知道一周后我已经合并了 153c2f ?我怎样才能以一种知道合并的方式进行挑选?
回答by Klas Mellbourn
How will you know?
你怎么知道?
Not by using git cherry
since it only recognizes commits that have the same git patch-id
(see man page), i.e. not those where you have had to resolve non-trivial conflicts.
不是通过使用,git cherry
因为它只识别具有相同git patch-id
(参见手册页)的提交,即不是那些您必须解决非平凡冲突的提交。
So you will have to know by looking at the commit message.
因此,您必须通过查看提交消息来了解。
How will future merges know about the cherry-pick?
未来的合并将如何了解樱桃选择?
Since you have resolved the conflict when you applied the cherry-picked change, then that commit should merge trivially when you merge the whole branch in the future.
由于您在应用精选更改时已经解决了冲突,因此当您将来合并整个分支时,该提交应该很容易合并。
If you are really concerned about git remembering how you resolved the conflict, you could enable git rerere:
如果你真的很担心 git 记住你是如何解决冲突的,你可以启用git rerere:
git config --global rerere.enabled true