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 +3424d 10h 17m
Italy 59d 12h 42m
Parker's 9th birthday 77d 02h 57m
My next birthday 158d 07h 02m
Categories
Aviation (358) Baseball (110) Best Bars (10) Biking (44) Chicago (967) Cubs (198) Duke (133) Geography (352) Higher Ground (5) Jokes (284) Kitchen Sink (689) London (66) Parker (198) Daily (204) Photography (148) Politics (304) US (1126) World (274) Raleigh (21) Readings (8) Religion (67) San Francisco (93) Software (210) Blogs (82) Business (242) Cloud (90) Cool links (147) Security (103) Travel (255) Weather (744) Astronomy (93) Windows Azure (62) Work (95) Writing (14)
Links
Archive
<March 2015>
SunMonTueWedThuFriSat
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234
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: 4737
This Year: 123
This Month: 40
This Week: 2
Comments: 0