Search code examples
gitmergesmartgit

SmartGit: Merge items I excluded/discarded on previous merge


Say I have my branch Alabama, that contains a set of changes (in files foo , bar and hello) compared to the develop which it is based on and I have a (fresh) branch Boston that is also based on develop which has no changes compared to develop yet.

Boston is my current local branch and I merged Alabama into my working tree, but discarded the changes to foo. I pushed, no conflicts, did a few other commits, everything is fine. Now I decide I need those changes to foo: I try to merge Alabama into my working tree again, but the changes to foo don't get merged since SmartGit seems to sort of remember that I decided to not use these changes and now automatically discards them for me.

What's the right way to get the changes to foo into Alabama? ;-)


Solution

  • One strategy to clean up your problem is to rebase the Boston branch on Alabama. Consider the following diagram:

    Alabama: d <- A1 <- A2
    Boston:  d <- M1 <- B1 <- B2
    

    Here the d commit is one commit (possibly of many) in the develop branch. You can see that both Alabama and Boston sit on top of this common history. The A commits correspond to the Alabama branch, and one or more of them contains the changes for the file foo which you want to bring into the Boston branch. The B commits correspond to the Boston branch. The commit M1 is the merge commit resulting from your attempt to merge Alabama into Boston while discarding the change for the file foo.

    If you rebase the Boston branch on Alabama, the diagram will look like this afterwards:

    Alabama: d <- A1 <- A2
    Boston:  d <- A1 <- A2 <- M1' <- B1' <- B2'
    

    Here are the commands to do this:

    git checkout Boston
    git rebase Alabama
    

    In other words, the work you did in the Boston branch will now be sitting on top of Alabama, which will include the changes to the file foo. The prime markings on some of the commits (e.g. B1') indicate that these are actually new commits in the Boston branch. Also, you may get merge conflicts during the rebase. In particular, expect conflicts when you replay the M1 commit on top of Alabama, since there will be very similar changes from both commits.