Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to back up local Mercurial repositories and use rebase?

Tags:

mercurial

My company is moving from Subversion to Mercurial. One of the reasons is with Hg we hope to be able to work more independently.

We are looking forward to using rebasing as our primary way to update from the main repository, at least in the beginning, to keep the history in one line, making the transition from Subversion easier.

Right now, if we need to work independently, we have two options: create a branch in Subversion, and commit there (aka merge hell), or not commit at all. With Mercurial we hope to be able to keep committing locally, and rebase every so often, thus gaining independence while staying free of the administration costs of bcreating named branches.

This all sounds cool until backing up comes into the picture. With Subversion it was obvious that if someone didn't commit, their work ccould be lost. But not committing became inconvenient quickly (no history, no log messages etc.), so people would commit time and again nevertheless.

With Mercurial it is going to be possible to go on committing and rebasing without pushing for extended periods of time, putting much more work at risk. So a question comes up: how to back up the stuff on developers' machines?

  • One solution would be to use some external backup software, but that doesn't sound like a very good idea.
  • We could also push to the main repo all the time (maybe even automatically?), but this would make it impossible to use rebasing, and would result in a lot of dangling heads in main.
  • We could push to a backup repo, and try to have only one head in the main repo. This sound a lot complicated.

Are there any other ways to do this? I'd like to find a solution that would let our developers use most of their Subversion knowledge in the beginning.

like image 766
Lóránt Pintér Avatar asked Oct 25 '10 19:10

Lóránt Pintér


2 Answers

Just to throw this out there: I think you're making a mistake. A linear history isn't a big deal and pull/merge is the much more normal mercurial workflow. Embrace a non-linear history and leave rebase for special occasions.

You say "With Mercurial we hope to be able to keep committing locally, and rebase every so often, thus gaining independence while staying free of the administration costs of bcreating named branches.", but in mercurial one uses unnamed branches for this, so there's no administration costs.

See http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/#branching-anonymously for an explanation of how unnamed branches created automatically will give you exactly what you want with zero hassle.

I know it sounds like too-good-to-be-true snake oil, but your folks can just hg pull and hg merge and hg push when they're through and without anyone having to think about branch names, or who has what clone, or anything, you'll have a coordinated center with disconnected work.

like image 152
Ry4an Brase Avatar answered Nov 12 '22 18:11

Ry4an Brase


You could also give each developer a repo:

https://example.com/repos/awesome-product
https://example.com/repos/awesome-product-wolever
https://example.com/repos/awesome-product-pintér

Where they can push to all they want.

It would mean a lot of dangling heads, but that's probably OK because nobody would look at them until it comes time to restore… Then you'd simply ask for only the ancestors of the current tip:

hg pull https://example.com/repos/awesome-product-wolever -r tip

If I were using this scheme, I'd set:

[paths]
backup = https://example.com/repos/awesome-product-wolever

in .hgrc/hgrc.

Alternatively, you could give each dev one overall backup repo by setting this in their global ~/.hgrc:

[paths]
backup = https://example.com/repos/wolever-backup
like image 39
David Wolever Avatar answered Nov 12 '22 19:11

David Wolever