Merging a small change into a branch

Currently, I have a stable master branch and a branch with big changes on certain classes.

When using the "changes" branch, I found an error that I also want to fix on the main branch.

I fixed this by changing only one line of code on the main server.

Now I want this patch to also be added to the "changes" branch.

After reading a few answers , it was suggested that the best option would be Rebase.

When applying git rebase master in the "changes" branch, git seems to be considering one of the conflicting files - a completely different file than before. Using mergetools --tool diffuse , I get the following diagnostics:

As you can see, there is one change in the first file, tons of changes in the second and, apparently, do not overlap with anything.

My question is: is there a way to merge a small change into a heavily modified branch without spending a lot of effort on resolving conflicts? If not, what is the best way to deal with this situation?

+6
source share
2 answers

You can use the cherry-pick method user3387542, this is a good way to do this, but not the only way. Another is that the error also exists on the main branch, and the last 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 

In any case, in any case, you balance the fix-graph mess with clear traceability (it's easy to say git branch --contains $somecommit to find out which branches contain the fix, it's not so simple and not necessary to look for equivalent commits, but much cleaner history.

+3
source

Take a look at the git cherry-pick command. Here's more about this:

http://git-scm.com/docs/git-cherry-pick

We often use it to copy patches to other branches containing different versions. This is a great opportunity.

+2
source

Source: https://habr.com/ru/post/979544/


All Articles