I currently have a stable master branch, and a branch with a lot of big changes on certain classes.
While using the "changes" branch, I discovered a bug I also want to fix on the master branch.
I fixed it by changing only one line of code on the master.
Now, I want to have this hotfix also added onto the "changes" branch.
Reading some answers, it's been suggested that the best option would be to Rebase.
When applying git rebase master
on the "changes" branch, though, git seems to consider one of the
conflicting files a completely different file than before. Using mergetools --tool diffuse
, I get the following diagnostic:
As you can see, there's one change in the first file, tons of changes in the second, and apparently no overlap between anything.
My question is: Is there a way to merge a small change into a heavily altered branch, without having to spend a lot of effort into conflict resolution? If not, what's the best way to handle this situation?
When you perform a merge, you effectively merge one branch into another—typically a feature branch or bug fix branch into a main branch such as master or develop. Not only will the code changes get merged in, but also all the commits that went into the feature branch.
No, merging does only affect one branch.
You can use the cherry-pick method user3387542 suggests, it's a good way to do it, just not the only way. Another is, since the bug also exists on the master branch the most recent merge base for the two also has it.
git checkout $(git merge-base master changes)
# fix bug at the last branchpoint
git commit -m 'fix bug #27182'
git branch bugfix-27182
git checkout master
git merge bugfix-27182
git checkout changes
git merge bugfix-27182
# git branch -d bugfix-27182
There's downsides either way, you're balancing commit-graph clutter with clear traceability (it's easy to say git branch --contains $somecommit
to find out which branches contain the fix, not so easy nor so certain to look for equivalent commits but a much cleaner-looking history.
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