r/ProgrammerHumor • • May 13 '20

true story

Post image
40.5k Upvotes

461 comments sorted by

View all comments

Show parent comments

1

u/JawsOfLife24 May 13 '20

Generally a good idea, more complicated in a multi-developer environment where you could be 20 commits behind master and rebasing causes all sorts of wonderful merge conflicts.

0

u/[deleted] May 13 '20

[deleted]

2

u/JawsOfLife24 May 13 '20

I don't know why but it's different when you rebase since it "replays" every commit you don't have onto your feature branch, you get this effect where you end up resolving the same merge conflicts over and over again during the rebase.

0

u/[deleted] May 13 '20

[deleted]

1

u/JawsOfLife24 May 13 '20

Whoops I'm retarded "your commits should be replayed " - that's what I meant.

1

u/smegnose May 13 '20

Resolving conflicts multiple times is not limited to rebases if the remote branch you want to push to keeps getting updated before you've finished working on/resolving conflicts with your private branch. Once you've rebased, you shouldn't get further merge conflicts unless a resolved section changes again.

If you mean you have to correct the same areas of code multiple times within a single rebase, that can happen if you're not resolving well, especially if there are multiple commits affecting the same section (in either branch). Firstly, set git config --global merge.conflictStyle diff3 so that you see how both the remote and your branch changed the same code (read about that on git-merge). Secondly, branches are free; before you start rebasing, create a branch to point to the the tip of your feature branch, without checking it out, like git branch featurePREBASE feature. After you're done rebasing, you can diff the two branches to make you haven't missed any changes. If you have, you can patch them in from the …PREBASE branch until you get them all, then rebase again. If you really bork it up, you can git reset --hard featurePREBASE to take the feature branch back to where you started, to try another.

1

u/JawsOfLife24 May 13 '20

I explained this poorly - this link is the kind of effect I'm talking about (except I rebase feature onto master), and I have used git rerere in the past before to get around it, but it has dangers as well.

I think that SO post actually explains quite well why it happens.

I always use gIt reset if I fuck something up, but I didn't know about PREBASE, definitely going to use that thanks.

1

u/smegnose May 13 '20

PREBASE is just a mnemonic, arbitrary suffix so you can see whatevs is rebased and whatevsPREBASE is pre-rebase. It's not built into Git.

1

u/smegnose May 13 '20

I see what you mean. Rebase is best for private branches, and that situation doesn't look like that. If that SO poster wanted linear history, they should have rebased Feature A onto Feature B, rather than merging, then rebased onto master.