Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can git tell me if a rebase will conflict without actually rebasing?

Tags:

git

rebase

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 --aborting 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?

like image 339
Tom Ellis Avatar asked Jul 06 '17 15:07

Tom Ellis


1 Answers

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.

like image 184
Mark Adelsberger Avatar answered Sep 27 '22 19:09

Mark Adelsberger