0

when using git cherry-pick,occur a conflict.
the conflict cause by the target branch is short of the work branch.
lack of some commit ,I can't cherry-pick my new commit to the target branch .
the question is how can i find which conflict commit , When i cherry-pick my new commit to target branch which is lack of some commit, and list the confilct commit ID ?

I m sorry for my pool English.

Branch A, whith commit 1,2,3,4,5,6
Branch B, with commit  1,3

commit 6 is a associate with commit 4. when I cherry-pick commit 6 to branch B, the conflict occur.

Is there have any easy way to figure out which commit is associate commit 6. so that i can cherry-pick this commit (like commit 4),and than cherry-pick commit 6, instead of commit 4 & 5 both.

Thank you for all.

SITU
  • 3
  • 2
  • http://stackoverflow.com/q/42531657/2303202 – max630 Apr 22 '17 at 04:02
  • @SITU what do you mean commit 6 is a associate with commit 4? Do you mean both 4 and 6 modify the same files or 6 is merged from 4? BTW, even it shows conflicts during rebase, you can solve the conflicts manually or automatically to finish the cherry-pick. And it will be more clear if you illustrate your branches structure by grah. – Marina Liu Apr 24 '17 at 07:40
  • modify the same files. like @Mort say, i want to find a more efficient way – SITU Apr 24 '17 at 14:43
  • @SITU I give the answer to find the earliest commit which add/modified a certain file. Please have a try. – Marina Liu Apr 25 '17 at 07:10

2 Answers2

0

I was going to edit your question, but the edit was so complete, that I would have rewritten your original question.

Perhaps it is this:

"When attempting to git cherry-pick A, I get a conflict. This conflict is because commit B, an ancestor of A is not in the destination branch and without it, commit A results in massive conflicts in the destination branch. How do I identify commit B?"

This is not a git question, this is a general revision control question. There might be just one commit that blocks A from going into the destination branch cleanly (or even with small conflicts) or there might be several commits blocking A. Look at the conflicts when doing the cherry-pick, and look at all the files changed in A, and do a git log A -- <file> on each and try to figure out what would fix that conflict. Then try cherry-picking various combinations git cherry-pick B A until you find something that works.

Mort
  • 3,379
  • 1
  • 25
  • 40
  • thank you very much. that is a way to fingure out .but ,When A has large files changed, it is too hard to do this. especially many commit is associate with A. – SITU Apr 22 '17 at 06:18
  • Hard problems have hard solutions. In your example above, the programmatical approach to solving the problem is to figure out all commits not in `B` : `(2,4,5)`, and try all combinations of them (including multiple ones) to see what makes `6` go in. – Mort Apr 22 '17 at 14:33
0

If you want to find the commit which original add/change a file on branch A before cherry-pick. You can use:

git log B..A filename

This command will output the commits which modified the file and the commits only belongs to branch A. You can find the earliest commit in the bottom of output, and then cherry-pick this commit on branch B:

git checkout B
git cherry-pick <the earliest commit you found>
Marina Liu
  • 36,876
  • 5
  • 61
  • 74