I use a lot of local topic branches in git, and sometimes end up with dependencies between topic branches causing rebase problems. For example, with a structure like:
master ---> featureA ---> featureB
\--> featureC
If master
changes and I get (and resolve) conflicts when rebasing featureA
, then afterwards rebasing featureB
onto featureA
triggers the same conflicts (and sometimes exciting new ones as well) because it tries to reapply the patches from the featureA
branch. Assuming that the actual patches between featureA
and featureB
would apply cleanly if cherry-picked, is there a way of doing a rebase in this situation with roughly the same effect as cherry-picking all of the commits between featureA
and featureB
?
If the feature branch you are getting changes from is shared with other developers, rebasing is not recommended, because the rebasing process will create inconsistent repositories. For individuals, rebasing makes a lot of sense. If you want to see the history completely same as it happened, you should use merge.
1 Answer. Show activity on this post. Case 1: We should not do Rebase on branch that is public, i.e. if you are not alone working on that branch and branch exists locally as well as remotely rebasing is not a good choice on such branches and it can cause bubble commits.
From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.
You can rebase your feature branch directly from the merge request through a quick action, if all of these conditions are met: No merge conflicts exist for your feature branch. You have the Developer role for the source project.
The Golden Rule of Rebasing reads: “Never rebase while you're on a public branch.” This way, no one else will be pushing other changes, and no commits that aren't in your local repo will exist on the remote branch.
After rebasing featureA
, you can do
git rebase --onto featureA oldFeatureA featureB
assuming oldFeatureA
represents the commit at the tip of featureA
before you rebased it (you can either keep another branch there or just remember the commit hash).
This should basically be the same as cherry-picking each commit between A and B onto the rebased version of A.
Documentation on git-rebase (includes some helpful pictorial explanations of what happens during some more complex rebase operations)
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