Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm basing my Git repo on A successful Git branching model and was wondering what happens if you have this situation:

enter image description here

Say I'm developing on two feature branches A and B, and B requires code from A. The X node introduces an error in feature A which affects branch B, but this is not detected at node Y where feature A and B were merged and testing was conducted before branching out again and working on the next iteration.

As a result, the bug is found at node Z by the people working on feature B. At this stage it's decided that a bugfix is needed. This fix should be applied to both features, since the people working on feature A also need the bug fixed, since its part of their feature.

Should a bugfix branch be created from the latest feature A node (the one branching from node Y) and then merged with feature A? After which both features are merged into develop again and tested before branching out?

The problem with this is that it requires both branches to merge to fix the issue. Since feature B doesn't touch code in feature A, is there a way to change the history at node Y by implementing the fix and still allowing the feature B branch to remain unmerged yet have the fixed code from feature A?

Mildly related: Git bug branching convention

share|improve this question
6  
Can't you just fix the bug in the 'develop' branch and then merge it into both feature A and feature B? –  tdammers Jun 24 '12 at 10:42
    
Hmm, seems like that would be best. There might be merge conflicts in feature A but I think that's inevitable here. –  Aram Kocharyan Jun 24 '12 at 10:46
    
If you haven't done any further development on the 'development' branch, and the bugfix does not overlap any changes in the 'feature A' branch, then you won't get any conflicts. –  tdammers Jun 24 '12 at 10:48
add comment

3 Answers

up vote 19 down vote accepted

Fix the bug in one branch, then cherry-pick that commit into the other branch.

share|improve this answer
    
That works well, cheers. –  Aram Kocharyan Jun 24 '12 at 14:06
add comment

Arguably, there is no bug in A or X. Fix the bug in branch B where it was found. The fix will propagate to X and A in the normal course of events.

share|improve this answer
    
Thanks, that's also feasible as long as the bug doesn't affect feature A. –  Aram Kocharyan Jun 25 '12 at 13:38
add comment

Although not a popular workflow in git, a workflow which is popular in Mercurial would be to update to revision X, fix the bug there (as X2) and then redo merge Y (which would have been a pair of merges in Mercurial).

In fact, this workflow is easier in git since after everyone has switched from Y to Y2 then the refs to the original Y will be lost and it will eventually be garbage collected. In hg you would have had to manually strip those commits to tidy up your repository.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.