Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging small change into branch

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?

like image 379
ememorais Avatar asked Dec 13 '14 17:12

ememorais


People also ask

What happens when merging branches?

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.

Does merging affect both branches?

No, merging does only affect one branch.


1 Answers

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.

like image 77
jthill Avatar answered Oct 06 '22 08:10

jthill