Git – Fixing a Bug Affecting Two Branches

branchingbuggit

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

Best Answer

Use a distinct commit to fix the bug in one branch, then cherry-pick that commit into the other branch.