How do I reconnect a Git branch that has separated from master? (And duplicated its parents?)
This is a complicated situation, but essentially what has happened here is that our branch has become separated from master. So essentially:
A - B - C master \ X - Y - Z feature
has turned into:
A - B - C master (A) - (B) - X - Y - Z feature
The SHAs are the same for A/(A) and B/(B). This is exactly how it appears in GitK. At this point, I’m just trying to essentially put it back in the same order it was previously. Unfortunately, since the SHAs appear to be identical, I don’t know how I can manipulate X to branch out of B instead of (B). I honestly don’t know where to begin attempting this recovery. How can I reconnect the two branches at commit B?
Note that I have seen this question but it seems to be a slightly different issue, because the sha-1 of B and (B) are the same, since it has not been changed.
If you are sure the A/(A) and B/(B) are the same SHA hash, then I don’t see what the issue is, as X’s parent is B === (B) according to your diagram.
Is this all on a local repository? Are there any remote bare repositories involved?
Try running from the following to show the graph and put it in your question:
git log --graph --oneline --all
I replicated your setup with simple pushes and commits and this command gives (from the feature branch) :
* 86bf1b1 added Y on feature * a690031 added X on feature | * a7347fe added C on master |/ * d02c518 added B * 7d81e39 added A
If the SHA commits are as you suggest, you should see the same behaviour. If not, post an update with the isolated area you see at issue.
Answered By – Mark Fisher