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 +3364d 20h 40m
Berlin 11d 09h 08m
Parker's 9th birthday 136d 16h 33m
My next birthday 217d 20h 38m
Categories
Aviation (352) Baseball (110) Best Bars (9) Biking (44) Chicago (937) Cubs (197) Duke (133) Geography (341) Higher Ground (5) Jokes (284) Kitchen Sink (672) London (59) Parker (195) Daily (204) Photography (145) Politics (303) US (1110) World (261) Raleigh (21) Readings (8) Religion (66) San Francisco (93) Software (209) Blogs (78) Business (235) Cloud (90) Cool links (138) Security (101) Travel (244) Weather (717) Astronomy (91) Windows Azure (61) Work (92) Writing (10)
Links
Archive
<January 2015>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Full archive
Blogroll
About
David Braverman and Parker
David Braverman is the Chief Technology Officer of Holden International 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 ©2015 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: 4654
This Year: 40
This Month: 40
This Week: 8
Comments: 0