简体   繁体   中英

Is it possible to merge after cherry-pick and rebase?

Is it possible to merge at step 4 without conflict?

  1. cherry-pick commit 'E' from branch1 to branch2

     branch1: A - B - C - D - E \ branch2: F - G - E(cherry-pick from 1)
  2. The commits are added to branch2

     branch1: A - B - C - D - E \ branch2: F - G - E - H - I
  3. Rebase interactively and squash commits because they are the solution to the same problem.

    (Now, I think it was bad decision...)

     branch1: A - B - C - D - E \ branch2: F - G - I'
  4. Cherry-pick squashed commit again to branch1...

    (Would it be better to cherry-pick commit H, I to branch1?)

     branch1: A - B - C - D - E - I'(conflict?) \ branch2: F - G - I'

This is an interesting question, but nobody will be able to provide a definitive answer unless you were to provide the actual git repository so the changesets could be examined.

The fact that there is a merge conflict has nothing to do with whether commits H and I are cherry picked individually or are rebased together. The fact that E got squashed as well might be a factor.

More importantly, though, is a small problem with the premise of the question. "Is it possible to merge without conflict ?" Why does this merge need to happen without conflict? It's probably correct and appropriate for there to be a conflict.

When git says "there's a conflict", that does NOT mean "you messed up, these can't be merged." Rather, it means "I (git) can't figure out how these changes should be merged. I need human help."

Here's the solution : Get some good diff/merge software (I use P4Merge on Windows, but there are lots of options). Examine the contents of each of the commits in question. Understand what the conflict is (most likely H or I changed a line that had been changed in E, or maybe H and I depend on changes that had already been made in F or G). Resolve each conflict: this may mean keeping the original line, or keeping the newer line, or modifying the line in a new way that incorporates changes from both branches - it's entirely context dependent.

Don't be afraid to consult with team members on conflict resolution - chances are you'll be deciding if some of their work is going to get erased.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM