2

I've a master branch. It's the on-production code.

Every 'hotfix' must start from this branch

I've a develop branch. It's the 'stable-next-release' code.

Every new feature must start from this branch and is merge ONLY with this branch.

Today I take a mistake: I branched-off from develop for an hotfix.

Now I really need to apply the same modification to master branch, but I cannot merge the new hotfix branch because this will release every new feature already in develop.

Is there a way to ... sorry for bad words ... get a diff from develop and hotfix and the apply this modifications to master?

Is this probably what is called 'creating a patch' ?

jordelver
  • 8,292
  • 2
  • 32
  • 40
realtebo
  • 23,922
  • 37
  • 112
  • 189
  • So you have a branch that contains the changes for the fix? `rebase` might help if you haven't pushed that branch. – Sven Mar 14 '14 at 08:59
  • i've master, untouched, develop untouched, hotfix branch started from develop, and it's already commited and pushed. I need a way to apply the modifications to master instead of to develop branch. – realtebo Mar 14 '14 at 09:01
  • Can't you use cherry-pick ? http://stackoverflow.com/a/3933416/2454790 – BENARD Patrick Mar 14 '14 at 09:01

3 Answers3

3
  1. If you are dealing with only a few commits, then you can cherrypick your commits to the other branch

    git checkout  master_branch
    

    now, identify the commits that were added to the development_branch and using the SHA (commit Ids) of those new commits, just cherrypick the commits:

    git cherry-pick <SHA>
    
  2. If you are dealing with lot of commits, and you are fine with not retaining the original commit messages, then you can follow the diff-patch approach:

     git diff master_branch..development_branch > patch
     git checkout  master_branch
     git apply --check fix_empty_poster.patch  // dry run your patch
     git am --signoff < patch
    
brokenfoot
  • 11,083
  • 10
  • 59
  • 80
1

You could cherry-pick the hotfix from its branch:

git checkout master
git cherry-pick hotfix
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

As the other answers suggest, if it is only one (or a couple of) commits, then cherry-pick works fine. Otherwise you can do the following, which will retain the original commit messages:

git branch master_hotfix your_hotfix_branch
git rebase --onto master `git merge-base develop master_hotfix` master_hotfix
git checkout master
git merge master_hotfix

This makes a new "copy" of the hotfix branch based on develop and moves it over to start from the master branch instead where you then can merge it.

hlovdal
  • 26,565
  • 10
  • 94
  • 165