Jump to content

  • Log In with Google      Sign In   
  • Create Account

Proper usage of branching in [hg]mercurial


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Servant of the Lord   Crossbones+   -  Reputation: 19572

Like
4Likes
Like

Posted 16 July 2013 - 12:28 PM

Hey, so, after years and years of avoiding revision control software because of the (admittedly minor) learning curve and misunderstandings on my part, I started using Mercurial earlier this year, and really find it easy to use, easy to understand, and overall really pleasant and friendly. That is, the command-line interface. The TortiousHG interface got in my way too much and I kept stumbling over it*.

 

I've committed 113 times already (Woot!) I commit at least once a day, but sometimes twice or more, whenever I come to logical points to commit.

 

Where I've had trouble is with the idea of branching. I understand the concept, and I understand why it would be useful, but suppose I have several development branches: "Development" (or 'trunk' or 'main' or whatever the correct term is) , "ExperimentalFeatureX" and "UnfinishedFeatureY".

 

Suppose I'm currently in UnfinishedFeatureY working on it. If I fix a bug that's unrelated to FeatureY, I want to make sure that bug is fixed in Development. How can I merge just that one bug fix (or just that one file) into Development?

 

Here's another situation that worries me. I have all my art assets in the revision control system also. What if I'm working in ExperimentalFeatureX, add some new art, then cancel the experimental branch and close it, forgetting my art assets are in there? Is there a way I can add certain files to every active branch at the same time?

 

*I always have a weird relationship with tools - I want X amount of control, but don't want Y amount of complexity. Many tools dumb things down so much that the control I want either is blocked (with the tool taking control for itself), or hidden behind dozens of GUI commands that make it more complex to accomplish what should be (and is) an easy task.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


Sponsor:

#2 Ravyne   GDNet+   -  Reputation: 7409

Like
2Likes
Like

Posted 16 July 2013 - 02:26 PM

I'm no Distributed Version Control System expert, but in my experience with git, I tend to use "main" branches in a way that sort of facilitates the idealized waterfall model of development -- that is, I have a stable, test, and merge branch that run in parallel through the life of the project -- and feature work is branched off individually from the merge branch. So, a feature is completed and tested in isolation, is promoted to the merge branch where any changes necessary to merge the feature happen (will branch those off too), that gets committed, and then promoted to the test branch (new tests written, etc), and when all is well there the whole shebang gets promoted to stable. That's just one of many ways you can use DCVSs.

 

In general, the idea of DCVSs is that you should be creating branches literally all the time, even as a single developer. New feature or experiment? New branch. If you just do a linear progression of code, the benefits of DVCSs tend to fade, but the flexibility of DVCSs really enables you to use whatever workflow you want -- even one that behaves more like a traditional Centralized VCS.

 

As to art assets -- I believe pretty firmly that the distributed model of version control systems isn't terribly suited for art assets. As such, I actually prefer to keep them separately in a Subversion repository. This is for a couple reasons: Firstly, the centralized checkin-checkout model seems more suited to artists workflow, secondly, few artists really grok the concept of branch-merge and how it affects their workflow, thirdly, an individual artist doesn't need the source artwork and history for all assets and the amount of data is huge. Finally, you don't have to worry about a non-technical person borking your entire source code tree. 



#3 Servant of the Lord   Crossbones+   -  Reputation: 19572

Like
0Likes
Like

Posted 16 July 2013 - 02:40 PM

For the artwork, the reason why I have it in the mercurial repository is merely because my entire project is in there. It's a backup of my entire project that can be rolled forward or rolled back. I don't need the history of individual pieces of art, but using two separate source control systems seems like an unnecessary complication that'd confuse me alot! Would one VCS then contain the other VCS's repository? huh.png

 

I get what you are saying about a feature getting completed in isolation and then merged - that's what I'd like to do... But what seems to happen to me alot is that if I'm working on the feature in a separate branch, and I make a non-feature-related bug fix or add a new helper function to the common/core library that's unrelated to the feature, I need to somehow make that bugfix or function addition be applied to the main branch immediately, instead of when the feature branch gets merged, if it gets merged at all. How do you handle that kind of situation in your workflow?


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#4 Ravyne   GDNet+   -  Reputation: 7409

Like
0Likes
Like

Posted 16 July 2013 - 02:48 PM

Personally, I don't find it too confusing to have a separate VCS for art, but I get what you're saying -- personal preferences and all.

 

I think the main thing with DVCSs is that you really have to commit to a certain worldview, and be pedantic about it. In your example, if you found that you suddenly needed to make a fix that's not really part of the feature work, the "prescribed" approach would be to quickly make a different branch for that thing (from whatever other branch is appropriate), and then go back to your feature branch and pull that change you made back down into the feature branch. I forget exactly how you do this, but that's the workflow that hg/git pros would probably recommend.



#5 Servant of the Lord   Crossbones+   -  Reputation: 19572

Like
0Likes
Like

Posted 16 July 2013 - 08:15 PM

In your example, if you found that you suddenly needed to make a fix that's not really part of the feature work, the "prescribed" approach would be to quickly make a different branch for that thing (from whatever other branch is appropriate), and then go back to your feature branch and pull that change you made back down into the feature branch.

So, I'm in 'FeatureX'. I have to:
- Commit my current changes in FeatureX (if I forget this step, and I lose work) (hg commit -m "saving my progress")
- Switch over to the stable branch (hg update StableBranch)
- Branch the stable branch into TinyFixQ (hg branch TinyFixQ)
- Change one line of code
- Commit the change (and remember to --close-branch) (hg commit -m "Fixed the thing" --close-branch)
- Change over to the stable branch again (hg update StableBranch)
- Merge TinyFixQ into the stable branch (hg merge TinyFixQ)
- Commit the stable branch (hg commit -m "applied the fix to the stable branch")
- Change back to FeatureX (hg update FeatureX)
- Pull TinyFixQ into FeatureX (hg merge TinyFixQ)
- Commit to FeatureX (hg commit -m "applied the fix to the developmental feature")

And then be back on my merry way! Did I miss a step? You can why I find it easier to just develop on a single branch.

There has to be a more succinct way to do it - I'm sure it's just my inexperience with Mercurial that makes it require so many steps.

 

Maybe I can use the graft command for this?

- Commit my current changes in FeatureX (if I forget this step, and I lose work) (hg commit -m "saving my progress")

- Write the bugfix

- hg commit -m "Fixed bug" (and remember the revision number)

hg update StableBranch

- hg graft <revision-number>

hg commit -m "applied the fix to the stable branch"

hg update FeatureX

 

Does that work? Did I get it correct? If so, it saved me a number of steps... but is still too many.

 

Why can't I just go:

- Commit my current changes in FeatureX (if I forget this step, and I lose work) (hg commit -m "saving my progress")

- Write the bugfix

hg commit -m "Fixed bug" (and remember the revision number)

hg graft <revision-number> StableBranch --and-commit (grafting and committing the single revision to a different branch than the one I am in, without me having to change between branches)

 

The red underlined part is stuff I'm making up. Are there any equivalent commands?


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#6 Ravyne   GDNet+   -  Reputation: 7409

Like
0Likes
Like

Posted 16 July 2013 - 08:44 PM

I lack the hg-fu to tell you how to do this easily, but as best as I understand, the whole idea of fast branch and merge is that you have easy atomic sandboxes, and you're meant to use them. They're argued to be lightweight enough that its not a hassle. Its more or less a matter of policy just how related a change has to be to be considered part of an existing atomic unit or its own, but if by whatever standard it is "different" then it ought to be in a different branch logically, otherwise your history is a tangled mess of things.

 

By that same token, you shouldn't ever be making "intermediate" commits with partially complete features to save your progress -- if you're doing that, you're using the tool in a fundamentally wrong way. One which is not much better than a glorified backup. A commit is all or nothing, it implements a some subset of code completely. You might break a large functional area down (possibly using sub-branches, even) into smaller pieces, but they're always "complete" for some definition of complete -- a commit should never represent an interruption.

 

If you have some misunderstanding about how to best use these tools, you wouldn't be the first. I'm certainly no authority. But the way of working that's prescribed by DVCSs is markedly different than Centralized VCSs, and to most simple ways that people have collaborated in the past. It sometimes seems completely insane to have to do all these little steps up front to do seemingly simple things, but the argument is that the cost you pay now is less than the delayed cost of heavy branches and endless merge conflicts under the old paradigm.



#7 wintertime   Members   -  Reputation: 1715

Like
1Likes
Like

Posted 17 July 2013 - 03:38 PM

I think the workflow could be more like this, that would prevent polluting the repository with temporary things:

hg shelve

hg up stable

edit in the fix

hg commit

hg up devel

hg unshelve

hg commit

hg merge

 

Btw., branches in mercurial are like svn branches and are meant to be long running things which are not removed, like for example the default branch for developing, a stable branch for the next oldest version which just gets bugfixes or similar. For adding a single feature or bugfix you can use bookmarks, which are more similar to git branches and can be deleted when you dont need them anymore.



#8 Servant of the Lord   Crossbones+   -  Reputation: 19572

Like
0Likes
Like

Posted 17 July 2013 - 04:12 PM

I think the workflow could be more like this, that would prevent polluting the repository with temporary things:

 

Slightly altered from actual quote:

hg shelve 
hg update Stable
edit in the fix
hg commit
hg update ExperimentalFeatureX
hg unshelve
hg commit
hg merge

 


I'm not sure I understand. ('shelve' is a Mercurial extension)

 

'shelve' just stores away what I was working on without committing, right?

Why not just commit?

And how does the bugfix or feature addition that I'm making to Stable get back into ExperimentalFeatureX at the same time? I want to commit changes made to a specific file into both branches.

 

Also, what's that merge for at the end? I'm not wanting to merge ExperimentalFeatureX into Stable - at least not yet. Or are you merging Stable into ExpermentalFeatureX, to bring ExperimentalFeatureX up to date? Huh, I *think* I get that.

 

But why use shelve at all? Why not just:

  1. hg commit
  2. hg update Stable
  3. edit in the fix
  4. hg commit
  5. hg update ExperimentalFeatureX
  6. hg merge

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#9 Ravyne   GDNet+   -  Reputation: 7409

Like
1Likes
Like

Posted 17 July 2013 - 04:27 PM

commit means you're putting that interruption into your history. That's not something you want to preserve; right now you care about coming back to that point in your would-be "history" so you can pick back up on feature work, but tomorrow or 6 months from now you're never going to want to come back into the point where you were interrupted. Every time you commit, you're creating a mile-marker that you can return to should ever the need arise. You don't want to litter the roadside with irrelevant markers -- its particularly harmful if you wanted to go back in history to a point *just before* the next feature you add, which you would logically assume is commit X-1 -- but committing the interruption would actually make it commit X-2.

 

shelve gives you the same kind of workflow without polluting your history.


Edited by Ravyne, 17 July 2013 - 04:29 PM.


#10 wintertime   Members   -  Reputation: 1715

Like
0Likes
Like

Posted 18 July 2013 - 04:32 AM

Yes, thats why I was suggesting this.

 

The merge at end could be different things depending on how you want to continue. Possibly merging the fix and then the feature into default development branch, merging the feature into the stable (though that would be a little weird naming for a branch where you add new features) or merging the fix into the feature branch at a logical point when/if you need it there to continue developing that feature. Not completely sure if that works on mercurial but you could also merge over the fix before unshelving to have the branches a little less intermingled.



#11 Servant of the Lord   Crossbones+   -  Reputation: 19572

Like
0Likes
Like

Posted 18 July 2013 - 10:59 AM

I'm still not seeing how the patch gets applied to both the Stable and the Development branch?

  1. hg shelve <-- Checkpoint current ExperimentalFeatureX work
  2. hg up stable <-- Load the stable branch
  3. edit in the fix <-- Fix the bug or add the function into the stable branch
  4. hg commit  <-- Save the stable branch
  5. hg up devel <-- Load the ExperimentalFeatureX branch. This unloads the fix I just did...
  6. hg unshelve <-- Reload the checkpoint of where I was before.
  7. hg commit <-- Save the work
  8. hg merge <--- What am I merging, exactly?

Sorry for being thickheaded, I just am not fully grasping how this accomplishes what I want (Adding a single patch into two or more branches, without merging the branches with each other). What am I missing?


Edited by Servant of the Lord, 18 July 2013 - 10:59 AM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#12 Shannon Barber   Moderators   -  Reputation: 1362

Like
1Likes
Like

Posted 18 July 2013 - 11:02 PM

If you are not maintaining releases and do not have many people working on the code-base, there is no reason to branch - especially not with a modern tool like hg or git.

In hg or git every commit is like a microbranch so you are already befitting in a small way from branch technology.

On small projects at home I never branch. At work we have to maintain a shitload of branches.

 

If you do a release then you should tag that commit (so you can find it easy) then if-and-when you need to fix a bug you can create a branch to support that release and release 1.0.1, 1.0.2, etc...

If the project is large and stable and you want to develop a big new feature, then you can create a 'development branch' to keep the experimental work on that branch until you deem it high enough quality to merge to the mainline.

 

If you have lots of developers simultaneously developing features then you can create 'feature branches' to keep each feature's development from interfering from one-another as they break things.

 

If you had to fix a bug in the 1.0 release then odds are it's still in the mainline code so you'd want to merge that bug fix back to the mainline.

 

If you make development branches then you want to periodically merge the mainline to the development branch first to work out compatibility issues on the development branch (made other people have merge big ass development branches in the mean-time.) Once you have a recent main->branch merge then you do a branch->main merge (this ensure the merge to main is easy).

 

When you're doing small feature branches you might just go-for-it and merge the feature back to the trunk (and if you have trouble, then abort the merge and merge the trunk to the feature branch).

 

I never use the command line for merge management; you really want to see what you are doing.

With hg, merging a branch is not really any different from merging two check-ins on the trunk.


Edited by Shannon Barber, 18 July 2013 - 11:08 PM.

- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

#13 Servant of the Lord   Crossbones+   -  Reputation: 19572

Like
0Likes
Like

Posted 19 July 2013 - 12:12 AM

Thanks everyone, this is really helpful.

If you do a release then you should tag that commit (so you can find it easy) then if-and-when you need to fix a bug you can create a branch to support that release and release 1.0.1, 1.0.2, etc...

Right, I forget about tagging

If you had to fix a bug in the 1.0 release then odds are it's still in the mainline code so you'd want to merge that bug fix back to the mainline.

How do you do that? Do you just merge the entire 1.x release branch back into the mainline?

If you make development branches then you want to periodically merge the mainline to the development branch first to work out compatibility issues on the development branch (made other people have merge big ass development branches in the mean-time.) Once you have a recent main->branch merge then you do a branch->main merge (this ensure the merge to main is easy).

That makes sense! I think I'm starting to understand.
 

I never use the command line for merge management; you really want to see what you are doing.

So far, I've never had any conflicts, since I haven't used Hg long. I'll definitely use something like WinMerge for sourcecode conflicts!
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS