Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cherry-picking with git with a conflict

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)

$ 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?

like image 559
szabgab Avatar asked Apr 17 '13 20:04

szabgab


People also ask

How do I resolve conflicts after git cherry-pick?

git cherry-pick <commit-hash> to cherry-pick a commit from another branch. git cherry-pick -n <commit-hash> to cherry-pick the commit but it won't commit the changes. It will only stage all the changes. git cherry-pick —continue or git cherry-pick —abort when you face conflicts while cherry-picking.

What happens if you get a conflict during a merge?

Merge conflicts happen when you merge branches that have competing commits, and Git needs your help to decide which changes to incorporate in the final merge. Git can often resolve differences between branches and merge them automatically.


1 Answers

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.

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 config --global rerere.enabled true
like image 75
Klas Mellbourn Avatar answered Sep 19 '22 23:09

Klas Mellbourn