1

I have two branches and one of them is always up to date with master by rebasing, but after a few changes I have some conflicts between two branches and rebasing got a bit painful. Now I wonder is there a way to get the latest commit from master, as I did a rebase?
I have this:

-- -- -- -- -- XX (Master)
             \
               -- -- -- -- -- (Branch 2)

I want a PAINLESS WAY to get this:

-- -- -- -- -- XX (Master)
                \
                  -- -- -- -- -- (Branch 2)

Rebasing asks to resolve set of conflicts while rewinding commits from Branch 2, though commit XX doesn't have any conflicts with commits on Branch 2. cherry-pick-ing creates new commit which I don't want to have, because it mixes up branches.

UserASR
  • 2,015
  • 4
  • 24
  • 47
iamawebgeek
  • 2,713
  • 1
  • 18
  • 34
  • What you are asking to do is to _rewrite_ the history of Branch 2, by introducing one or more new commits from `Master`, and then replaying commits on your branch on top of this. `git rebase` is probably the least painful way of doing this. If, as you say, there isn't much friction caused by the new commits in `Master`, then the rebase should go smoothly. – Tim Biegeleisen Jan 20 '17 at 06:36
  • Do you have something against simply merging master into branch2 instead of rebasing? – Joe Phillips Jan 20 '17 at 06:40
  • @TimBiegeleisen I want to shift a single commit to history of `Branch 2` without again applying commits with conflicts by merging again – iamawebgeek Jan 20 '17 at 06:41
  • @zazu You _can't_ do this in Git, you would need to reapply all subsequent commits in `Branch 2`. – Tim Biegeleisen Jan 20 '17 at 06:42
  • @JoePhillips it does not matter, I just dont want to merge conflicts – iamawebgeek Jan 20 '17 at 06:42
  • 1
    You're asking to rebase without conflicts, but the additional commit you want will cause conflicts. How do you expect that it will automatically work itself out? You can tell it to automatically resolve conflicts, but it wont necessarily be right. – jbu Jan 20 '17 at 06:52
  • @jbu no, I have conflict in a different file, which is not related to commit `XX` – iamawebgeek Jan 20 '17 at 06:55
  • 1
    oh interesting...have you tried --preserve-merges? http://stackoverflow.com/questions/25670519/git-rebase-preserve-merges-fails - I've never personally used it, but it seems interesting – jbu Jan 20 '17 at 07:08
  • @jbu wow, that worked like a charm, thanks a lot! I think now I get what was the problem – iamawebgeek Jan 20 '17 at 07:16
  • 1
    This link explained things really well: http://stackoverflow.com/questions/15915430/what-exactly-does-gits-rebase-preserve-merges-do-and-why . Since I've never used it, I would definitely read this carefully before using it. – jbu Jan 20 '17 at 07:18

0 Answers0