Question

Say I have two branches in Git: development and qa-test. Both of these branches contain different features - commits but also A is the latest common ancestor of these two branches:

A--->B--->C--->developent
\
 \
  D--->E--->qa-test

Now in some point we have found out that there was a bug in A, and we need to have fixed them both in qa-test and in development, i.e. we need to hotfix. One of the ways I can go is to create a new branch from qa-test names hotfix, fix there the bug, commit in into qa-test and then cherry-pick this into development. Is there a better way of doing this?

Was it helpful?

Solution

Create a branch from A and then merge the changes of the with qa-test and development.

$ git merge-base qa-test development 
sha-1 A
$ git checkout -b hotfix <<sha-1 A>>
... do changes and commits
$ git checkout devel
$ git merge hotfix
$ git checkout qa-test
$ git merge hotfix
$ git branch -d hotfix 

OTHER TIPS

Expanding on @Konstantin's answer:

$ git checkout A
... fix bugs ...
$ git checkout -b fix # creates a temporary branch for the fix
$ git commit

The state now:

  fix
 /
A -> B -> C -> development
 \
  D -> E -> qa-test

Now for the rebase:

$ git checkout development
$ git rebase fix # uproot development and stick it on the fix branch
... fix any merge conflicts ...
$ git checkout qa-test
$ git rebase fix # same for qa-test
... fix any merge conflicts ...

The state now:

A -> fix -> B -> C -> development
       \
        D -> E -> qa-test

If I'm doing something horribly wrong here, please let me know so I can fix this answer!

"rebase" will do that for you, fix bug in development branch, then rebase qa-test with development

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top