Friday, May 30, 2008

On History Rewriting

This is just a short note on history rewriting.

During my conversion process, I made some significant changes to the bzr-fast-export tool, as it can’t export some repositories by default. As I was hacking away quickly, I made some fast bzr commits, so that I could make nice patches out of them later on.

Today I wanted to do just that, but it appears to be impossible to rewrite your history with Bazaar. I would like to merge some commits, reorder them, change the log message and split one commit up in two parts. Also, I’ll have to adjust the author info, as I didn’t set it up correctly before.

Not too difficult, you’d think. However, I can’t figure out how to do it. The best thing I’ve found is bzr uncommit, which will return you to a previous state. In order to work with this, I’ll have to export a diff for every commit I did, then revert to the parent commit, apply a patch, and commit it again. If I want to split up a commit, I’ll either have to install and use the shelve plugin , or split up the patches myself.

Compare this to Git’s excellent rebase —interactive script. It will allow you to do everything I just mentioned, and then some. This has obvious advantages: you don’t have to worry about your patch series until you’re done with it. Some changes might not be obvious from the start, and being able to edit a log message to make it more clear as valuable tool. With Bazaar, once you’ve committed, you’re pretty much committed to it (pun intended). You’ll have to think ahead of time what you’re going to commit, in what order, and with what message. Obviously I prefer the freedom of Git in this case.


Jakub Narebski said...

Beside git rebase --interactive, which is useful for rewriting single short topic/development branch, there is also git filter-branch (idea taken/ported from Cogito's cg-admin-rewrite-hist), which allow to modify whole history using scripts, for example to remove accidentally checked in large binary file, or to correct history to follow grafts.

Mercurial has equivalent of plain git-rebase as transplant extension; I don't know about equivalent of git rebase --interactive

ga said...

I too am finding the rebase functionality lacking -- was looking for the reorder capability in git.

Actually, I prefer Bazaar's rebase for a very common problem -- moving your commit history after the upstream's.

I'm surprised history reordering hasn't been built for Bazaar though as it's such valuable feature.