20.4.16

Iterative rather than monolithic rebasing

In large open source projects, you often see this pattern.  Lets take a fictional source repo where people build Monsters.

  • I'm working on GodzillaMonster patch.
  • Someone else is building a new patch that makes MonsterCreation easier.
  • Their framework lands before my patch, meaning i have to rewrite Godzilla.

Ok, so now all my API calls in GodzillaMonster have changed, maybe like this...
 
shootLasersOutOfMouth

To

monsterFramework.shootLasersOutOfMouth

This would lead to a massive diff. because monsters LOVE to shoot lasers everywhere.

So the net effect, if I have a lot of new conceptual code underneath trivial refactors, is that the diffs become REALLY unnecessarily big, because git can't align them effectively !

This might be a tricky merge for git to understand because the line numbers have moved around a little bit.  In particular, you can see that the "hi this is godzilla" line isn't really aligned in an intuitive way. 

The trick

So, my trick is to do the following.
  • do a "pull --rebase"
  •  when it fails, open the file with the diffs in it.
    • find a few trivial changes that git wasn't able to align properly, but that are high frequency.
    • "git rebase --abort"
    • make all the trivial changes you found above, and save the file
    • git add, git commit, and git rebase down to one commit.
    • continue looping until rebase doesnt fail .
  • Eventually you're diff will be really simple one liners... like this. So the only diff mangling you actually do is on a file like this... with small one line changes .
 
Which is wayyyy easier to merge ! 

I know this sounds like you just moved the hard work from one place to another, but its not ! the reason this is way easier, is that each time you add a few incremental changes, you dramatically can help git do a better alignment.  So, each rebase you can do with much more confidence.  This is a super easy way to handle big diff blocks where you see that "some of the changes" in the middle of the blocks are easy to manage, but others are confusing.




No comments:

Post a Comment