Suppose we have the following situation in Git:
X---Y feature
/
A---B---C---D edge
Now I rebase the edge
branch changing the B commit a little bit (using edit
) so it now looks like this:
X---Y feature
A---E---C'---D' edge
C' and D' are the same commits as C and D, but applied on top of E (and notice that X within the feature
branch became disconnected).
Now how can I:
feature
branch so that its commits appear as if they were applied on top of D'?feature
branch so that its commits appear as if they were applied on top of E, but without a separate 'merging branch ...' commit (and with C' and D' being rewritten to become C'' and D'')?In a good workflow, the feature branch is deleted once its merged back into master. New branches should be created for each new feature(s) that you work on.
Merging Branches. Once you've completed work on your branch, it is time to merge it into the main branch. Merging takes your branch changes and implements them into the main branch. Depending on the commit history, Git performs merges two ways: fast-forward and three-way merge.
Merging is a safe option that preserves the entire history of your repository, while rebasing creates a linear history by moving your feature branch onto the tip of main .
X
doesn't become disconnected per-se, it still has the original B
as its parent. If you want to subsequently rebase feature
on top of edge
, then:
git checkout feature
git rebase edge
If you wish to change the tree so that it has a similar structure to the original version, but with X
as a child of E
, that's:
git checkout feature
git rebase --onto <sha-of-E> <sha-of-B> feature
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With