Is it safe to merge a branch created from an old commit in two, separate branches that are a lot more recent?

24 Views Asked by At

I have the following Git situation:

enter image description here

where:

  1. I was in commit A and, from there, I continued developing towards commit B.
  2. Arrived in commit B, I decided to create a new branch from the old commit A, ended with commit C.

Later, I found that both branches needed a fix. To do so, I was wondering if creating a new branch from commit A where developing the fix (let’s say, commit D), and then merging it into commit B and C could be the way to go:

enter image description here

Do you think it is a dangerous merge?

1

There are 1 best solutions below

0
Jay On

This is a perfectly fine approach.

Some people would prefer cherry-picking over merges, but that mostly comes down to personal preference. (duplicate commits vs. wide branch graphs)

Whether or not you'll have to solve merge-conflicts depends on whether the lines changed by D (or adjacent lines) where also changed in B and/or C.

Other than that I'm not exactly sure what you mean by "dangerous merge".