Reputation: 25691
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' ?
Upvotes: 2
Views: 350
Reputation: 28258
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.
Upvotes: 0
Reputation: 11649
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>
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
Upvotes: 3
Reputation: 312219
You could cherry-pick
the hotfix from its branch:
git checkout master
git cherry-pick hotfix
Upvotes: 1