Politics, Weather, Photography, and the Dog
Tuesday 11 March 2014

I just did a dumb thing in Mercurial, but Mercurial saved me. Allow me to show, vividly, how using a DVCS can prevent disaster when you do something entirely too human.

In the process of upgrading to a new database package in an old project, I realized that we still need to support the old database version. What I should have done involved me coming to this realization before making a bucket-load of changes. But never mind that for now.

I figured I just need to create a branch for the old code. Before taking this action, my repository looked a like this:

Thinking I was doing the right thing, I right-clicked the last commit and added a branch:

Oops:

Well, now I have a problem. I wanted the uncommitted changes on the default branch, and the old code on the 1.0 branch. Now I have the opposite condition.

Fortunately this is Mercurial, so nothing has left my own computer yet. So here's what I did to fix it:

  1. Committed the changes to the 1.0 branch of this repository. The commit is in the wrong branch, but it's atomic and stable.
  2. Created a patch from the commit.
  3. Cloned the remote (which, remember, doesn't have the changes) back to my local computer.
  4. Created the branch on the new clone.
  5. Committed the new branch.
  6. Switched branches on the new clone back to default.
  7. Applied the patch containing the 2.0 changes.
  8. Deleted the old, broken repository.

Now it looks like this:

Now all is good in the world, and no one in my company needs to know that I screwed up, because the screw-up only affected my local copy of the team's repository.

It's a legitimate question why I didn't create a 2.0 branch instead. In this case, the likelihood of an application depending on the 1.0 version is small enough that the 1.0 branch is simply insurance against not being able to support old code. By creating a branch for the old code, we can continue advancing the default branch, and basically forget the 1.0 branch is there unless calamity (or a zombie application) strikes.

Tuesday 11 March 2014 14:38:49 CDT (UTC-05:00)  |  | Software#
Search
On this page....
How to give yourself angina, Mercurial-style
Countdowns
The Daily Parker +3295d 04h 33m
Parker's 9th birthday 206d 08h 41m
My next birthday 287d 12h 46m
Categories
Aviation (342) Baseball (110) Best Bars (7) Biking (44) Chicago (903) Cubs (197) Duke (132) Geography (334) Higher Ground (5) Jokes (283) Kitchen Sink (651) London (54) Parker (191) Daily (204) Photography (144) Politics (303) US (1085) World (253) Raleigh (21) Readings (8) Religion (66) San Francisco (88) Software (203) Blogs (74) Business (226) Cloud (90) Cool links (133) Security (98) Travel (217) Weather (693) Astronomy (86) Windows Azure (59) Work (70) Writing (8)
Links
Archive
<November 2014>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
Full archive
Blogroll
About
David Braverman and Parker
David Braverman is a software developer in Chicago, and the creator of Weather Now. Parker is the most adorable dog on the planet, 80% of the time.
Legal
All content Copyright ©2014 David Braverman.
Creative Commons License
The Daily Parker by David Braverman is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License, excluding photographs, which may not be republished unless otherwise noted.
Admin Login
Sign In
Blog Stats
Total Posts: 4558
This Year: 456
This Month: 29
This Week: 10
Comments: 0