0

I have a problem where I've done the same bugfix on both the dev and this month's release branch separately, but because of architectural differences the fix is in different files on the two branches.

I'm following the http://nvie.com/posts/a-successful-git-branching-model/, which says to merge release branches back into dev, but since that fix has already been applied in dev, is there an easy way to "merge" but just keep what's in dev?

dev branch:      dev - changes - fix1a - moreChanges -?- justKeepDev
                   \                                     /?/
release branch:     release14.01 - fix1b ----------------
2
  • google for cherry-pick
    – zerkms
    Feb 3, 2014 at 0:05
  • @zerkms but I don't want to cherry pick anything, is the thing. I just want to register the merge.
    – Dax Fohl
    Feb 3, 2014 at 0:18

3 Answers 3

5

There's the ours merge strategy (not to be confused with the ours argument to the recursive merge strategy):

$ git checkout dev
$ git merge -s ours rel7

This will make a merge commit in branch dev, so that dev appears to have rel7 merged in, but will use all (and only) the files from branch dev. Whether that really gains you anything depends on how you use these: the point of doing such a merge is that if there's a later fix on rel7 that can be incorporated into dev with no changes,1 you can commit it to rel7 first, then later, git merge rel7 into dev to pick up the same fix in dev.


1In other words, the fix that went in as separate "fix1b" and then "fix1a" commits does not qualify. You were unable to simply merge in the fix1b change as it went into a different file/function/whatever. There was no advantage to fixing the problem in rel7 first, then merging rel7 into dev. (It's often hard to tell in advance whether this will be true, so you could try it as described below, and discover the no-advantage case afterward ... after which, well, you get to pick your poison as far as "how to do it" goes, there are no single best answers for such cases.)


The idea here is that you make the fix on the release branch first, then git merge that same fix into the development line. Making this "dummy" merge with the ours strategy simply sets things up so that the next merge does not attempt to bring in "fix1b".

Using the methods described on your linked page, you would have coded up "fix1b" first, on the release branch (or on a branch coming off the release branch), and tested and released it. Then you would have done a git merge to bring it into dev, and if that merge required changes, you might have made the changes as part of the merge (some people really dislike this method) or as a separate fix-up commit afterward (I dislike this one myself, it often leaves the merge commit itself broken or failing tests).

2
  • Right, implications for future merges was the primary concern; even if there are no more release branch updates, it could still cause problems when everything eventually syncs to master. Would have done it the way described, but when the bug was found dev had already diverged too much for that approach to be easy, so this seemed like the best alternate option.
    – Dax Fohl
    Feb 3, 2014 at 1:18
  • for fix1b, you can create a new branch from dev, merge released into this branch (no manual changes), fix in a new commit and then merge new branch into dev => that last merge will trigger CI tests that pass + code reviewers will see what was done by git and what were manual updates :)
    – Aprillion
    Aug 8, 2017 at 15:35
3

If I'm understanding you properly, the ours merge strategy should do what you want. From the documentation:

ours
    This resolves any number of heads, but the resulting tree of
    the merge is always that of the current branch head,
    effectively ignoring all changes from all other branches. It
    is meant to be used to supersede old development history of
    side branches. Note that this is different from the -Xours
    option to the recursive merge strategy.

To use this, do

git checkout dev
git merge -s ours release14.01
0

One way to do it is to revert fix1a and then subsequently merge your release branch directly back into your development branch. This will effectively undo all changes introduced by fix1a so that when you merge the same fix from the release branch, the fix there will go back to the development branch hopefully. If you are currently at moreChanges on your dev branch, and fix1b on your release14.01 branch, then something like:

git checkout dev
git revert (commit hash of fix1a)
git merge release14.01

If you need help visualising what the revert will do, I think the diagrams found here will be useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.