Take the 2-minute tour ×

I checked out the codebase on my desktop computer and worked some on it. Now Im going away and want those changes on my laptop.

One solution is to simply commit the incomplete code and then pull them on my laptop. But that would then mean that I have uncompiling code in the repos, something I would like to avoid.

Whats the best way to handle this? Generate and apply a patch? Using hg serve to move the incomplete change?

share|improve this question

4 Answers 4

up vote 4 down vote accepted

Here are three ways to do this. I'll discuss the pros and cons of each:

Option 1: use hg diff to get a diff file showing the uncommited changes, and then hg import --nocommit on the receiving end to apply those changes without creating a new changeset

  • Pros: simple, creates no changesets
  • Cons: doesn't actually use mercurial ike the DVCS it is. Might not catch newly added files

Option 2: Commit on the sending side, push to the receiving end (or pull from it, or put a hg bundle on a flash drive), bypassing the work server, update on the receiving side, and then hg rollback on both sides to eliminate the changeset (but leave the changes.

  • Pros: Using push and pull to move over changes like mercurial intends
  • Cons: Hacky. Relies on rollback which only works 1-level deep. Accidentally pull twice and you can't undo the first.

Option 3: Commit on the sending side. Push to a developer-repo that only you access, and Pull on the receiving end. Don't push to the company repo until things build, but when you do push push all the interstitial changesets

  • Pros: Exactly what a DVCS is about. Your order of work is documented and preserved
  • Cons: requires setting up a you-only clone

FWIW, I recommend option 3. Per-developer repositories are exactly what DVCSs are about. If your company doesn't make it easy to set one up on a server you can access from home and away, point out to them the immense value in having documented the process that got a developer to a completed fix/feature and that encouraging developers to push to a not-required-to-compile repo frequently is good for daily backups.

Lastly, after you're done with your feature or fix you can always collapse-away all the intermediary changesets. I don't like do it (I'm a show your work kind of guy), but here's how: http://stackoverflow.com/questions/1725607/can-i-squash-commits-in-mercurial/1725638#1725638

share|improve this answer
option 4, for advanced user: share a mq queue –  tonfa Nov 15 '09 at 17:44
Exactly the kind of answer I was looking for. Will be option 3 then, since I have already setup my own repository. I was just struggling a bit with the thought of having broken (uncompiling) changesets in my history. And I dont think collapsing changesets is a good idea, since the repository is public (in the way that I havent tried to make it hidden) someone may have cloned it, hence I should leave the history intact. –  Mizipzor Nov 16 '09 at 7:48
mizipzor, I think you're making the right choice. Rewriting history always feels sleezy to me even though it's a totally valid work mode. Sort of feels like doing science in pencil instead of pen. –  Ry4an Nov 16 '09 at 13:21

Hmm.... if you want the "head" to be clean then (and I may not get the terms right for Hg, I think in SVN, not done enough Hg yet):

Branch before your current round of changes, setting the you current work i.e. the stuff that doesn't build to be on the branch, commit the changes to the branch, pull the branch to the laptop, go, play, come back, then merge it all back together (which should be fairly trivial as the head won't have changed) and excise the branch if you really want to!

I've seen variations on this written up "in passing" several times - always held up as the reason why DVCS is "better" though it would probably take me the rest of the day to find you an example )-:

Alternatively (thinking a bit more - and allowing that I use SVN much more) - the key would be that I could commit to my local "WIP" repository all I want, broken code or not and therefore would pull (or push) my current WIP to the laptop and back safely. The repository that needs to be clean (to always build) is the "server" one so whilst I may commit locally I wouldn't PUSH to that repository - the server one - until its all good... (that "server" repository would then be the one that triggers the build server and so on). I suspect this latter is closer to most of the examples I've seen described.

share|improve this answer

Another cool option (but a little bit more involved) is to put the unfinished changes into an MQ (enable the mq extension first) and version the mq (qinit -c). Then, use qcommit to commit the current state of the patch queue and sync your unfinished work by pulling and pushing the mq.

share|improve this answer

It might be seen as uncultured, but I often use rsync to move "in-progress" repositories around over SSH until I get to a point where there is something worth committing.

share|improve this answer

Your Answer


