So, I have a maintenance branch and a master branch in my project. If I make a commit in the maintenance branch and want to merge it forward to the master branch, that's easy:
git checkout master; git merge maintenance
But if I want to go the other way around, i.e. apply a commit made to master back to my maintenance branch, how do I do that? Is this considered cherry-picking? Will it cause problems or conflicts if I merge the maintenance branch forward again?
This is exactly the use case for git-cherry-pick
git checkout maintenance
git cherry-pick <commit from master>
Alternate solution to using "git cherry-pick
" (as recommended in other responses) would be to create a separate [topic] branch for the fix off maintenance branch, and merge this branch first into maintenance branch, then into master branch (trunk).
This workflow is (somewhat) described in Resolving conflicts/dependencies between topic branches early blog post by Junio C Hamano, git maintainer.
Cherry-picking results in duplicated commit, which down the line may cause problems when merging or rebasing. Topic-branch based workflow keeps only one copy of the fix.
For complex commits that cannot be applied using git cherry-pick you can try
git checkout -b merge-branch master
git rebase --onto=`git merge-base master maintenance` HEAD~1 && git rebase master
Explained: http://blog.boombatower.com/automatically-backport-commits-using-git.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With