Don’t Lose Your Head With Bazaar

Here at SRT Solutions, we’ve become big fans of the distributed version control system Bazaar. While my personal experience with Bazaar has been very good overall, I ran into a very scary situation the other day.

I was away from a connection to our main Bazaar repository for a few days, so I had quite a few local commits saved up. When I was able to reconnect, I did a ‘bzr update’ to pull the latest revisions from our repository. A careful look at the output from the update command showed the startling fact that Bazaar had erased all of my changes. All the changes I made to existing files were reverted, all my new files were deleted, and all of my work from the past few days was nowhere to be found. At first, I wasn’t too worried, but the more I looked into things, the more I started to panic. ‘bzr status’ showed nothing. ‘bzr log’ didn’t mention my local commit messages. ‘bzr revert’ did nothing. It was like Bazaar forgot about all of my changes and erased them from the file system- not good for a version control system.

Help came in the form of Jay Wren who suggested that I try ‘bzr heads’. After fumbling with that command, I finally was able to get ‘bzr heads –all’ to tell me that I had a two heads. Each head was the root of a branch, so basically the output was telling me that there were two branches, my branch with the local commits (the dead branch) and the one that I just pulled from the repository with an update (the live branch). Here’s what the output looked like:

A simple ‘bzr revert -r revid:<my local rev-number>’ restored my changes and and my heartbeat. From there I was able to ‘bzr update’ again, and for some reason everything worked out fine this time. I’ve unsuccessfully tried to recreate this problem, but I think that it has something to do with mixing svn-style bound branches with unbound branches. At least I know that I won’t (wait for it) be loosing my head (groan) if this happens to me again.

8 Comments

The problem with bzr revert is that the changed files show up as modified/added/removed, and have to be checked in. `bzr pull` recovers the “lost” revisions themselves, along with commit messages etc.
Afterwards, run bzr update normally.

Thanks to bialix on #bzr for explaining and CaMason for bringing it up.