I would like to programmatically determine with of my feature branches would have rebase conflicts if I tried to rebase them. Is there a way I can get git to tell me this information without actually performing the rebase?
Failing that, what is the simplest way to detect if a rebase failed before git rebase --abort
ing it?
My question is similar to these two, which are the same but for merge instead of rebase
Can git tell me if a merge will conflict without actually merging?
Is there a git-merge --dry-run option?
The closest thing to a "dry run" of a rebase would be to run the rebase from detached HEAD state (so that no refs are actually modified). So instead of
git rebase develop feature_X
you might do
git rebase develop `git rev-parse feature_x`
and check the exit status. The problems with this approach are:
1) It's time consuming. Basically for any branch that doesn't conflict, the entire rebase will run. (And it's hard to imagine how you could do much less work and still accurately know whether the rebase would succeed anyway.)
2) It creates redundant objects (dangling commits and their dependencies), which won't be visible but will nonetheless hang around taking up space in your local repo until you either knock the dangling commits out of the reflog and run gc
, or create a fresh clone. If you do this often, the wasted space could really add up.
I'm also not sure how much utility this has. Just because feature_X
and feature_Y
would each rebase cleanly onto develop
, doesn't mean that the sequence of "rebase featureX
then rebase featureY
" will necessarily complete cleanly. And while it doesn't seem like it should be the case, after some things I've seen recently I wouldn't be shocked to learn of some edge case where the order of rebases determines whether there's a conflict.
So at best you'll get the "low hanging fruit" - "I know for a fact these have conflicts". But hey, you know, if that's the code you need, then that's the code you need.
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