Reclone mercurial subrepo - version-control

This seems like it should be really easy, but I can't find anything that directly addresses it in my searching. I have a mercurial repo with subrepos, I have deleted one of the subrepos (the whole folder). How do I reclone that subrepo now? I could do it manually but surely there's a hg command that does the job?

Use the Clean parameter in your hg update to make it pull the subrepo again.
hg update -C
Beware that clean will discard any uncommitted changes in your working directory, so shelve or commit anything you want to keep before doing it.

Related

What commands do you use to refresh your development environment with Mercurial?

I guess I'm learning somewhat backwards. I'm very comfortable with git and never used mercurial until my most recent project.
One of the things that bothers me is that sometimes I can't seem to refresh my development environment because of un-tracked file errors. I really don't care whether files are tracked/untracked on the development server. I'd just like to be able to pull the most recent state of the repo from bitbucket.
Unfortunately, I sometimes end up resorting to nuking the app and re-cloning. Normally this wouldn't be that big of a deal but there are dependencies that I need to add back to the app each time I do this because they are not stored in the repo.
With git I would run...
git reset --hard; git checkout master -f; git pull; git checkout origin/master -f
What's the mercurial equivalent? I've tried...
hg revert --all; hg pull; hg update;
Which seems to work as I would expect it sometimes. When it doesn't work it aborts due to the untracked file errors. I'm looking for something that works all the time.
hg up --clean
That's all there is to it. (hg up rather than hg update because hg is cooler than git and allows unique abbreviations. I dislike the way when I'm forced to use git it doesn't accept git ci like a sane version control system. I know I could make an alias... but I haven't ever got round to it partially as I don't use it very often at all)
hg help [command] (or hg [command] --help) is useful. The help for revert mentions that you probably want to use hg update -r rev or hg update --clean . instead.
This will only change tracked files. Untracked files will be left alone, which I think is what you want.

Hg (Mercurial): any way to "set aside" the working copy for later?

Scenario: After your last commit, you decided to do some extensive refactoring of the codebase. After a time, you realize it is taking longer than expected, and you'd really rather put off the refactoring for another time, and work on more pressing tasks. But you don't want to lose all of the refactoring work you've done so far.
So, is there a way to "archive" or "branch" the working copy (essentially, set it aside but keep it in the repository for later access), and then revert to the last good commit and resume from there, without fear of creating multiple heads or getting the two mixed up?
Don't worry about "the fear of two heads". Two heads is a very normal state. It's called anonymous branches, and it's one of the ways people do temporary branches in Mercurial.
Just commit, and then update to tip-1 and you're ready to go:
hg commit -m "working on XXX"
hg update -r "tip-1"
and away you go. If you want to drop a bookmark (less permanent than a tag) on that head you can, but there's no need to worry about it.
You can always push one head without pushing another using hg push -r HEAD where that can even be hg push -r .
Don't fear heads -- they're what makes a DAG based VCS powerful.
You can do this with the mq, attic or shelve extensions.
Assign a tag to your refactor revision
Commit the tag
Clone the repository again
Revert to the stable version
Work from the stable version
Don't worry about multiple heads, you can easily merge later
Since mercurial uses hard links, you can keep both repositories on your local machine with minimal space used.
commands:
$hg tag Refactor
$cd ..
$hg clone Refactor Stable
$cd Stable
$hg revert -r REVISION_NUMBER
extra help:
http://hgbook.red-bean.com/
http://kiln.stackexchange.com/
You can do it the simple way:
$ hg diff -g > tmp
$ hg revert --all
Your changes will now be stored in tmp. You can restore them with
$ hg patch --no-commit tmp
and you'll be back where you were. There are extensions like shelve that automates the above for you.
In git you would do a 'stash'. According to This hg has 'shelve', but it requires an extension.

Mercurial: How do you undo changes?

When using Mercurial, how do you undo all changes in the working directory since the last commit? It seems like this would be a simple thing, but it's escaping me.
For example, let's say I have 4 commits. Then, I make some changes to my code. Then I decide that my changes are bad and I just want to go back to the state of the code at my last commit. So, I think I should do:
hg update 4
with 4 being the revision # of my latest commit. But, Mercurial doesn't change any of the files in my working directory. Why not?
hg revert will do the trick.
It will revert you to the last commit.
--all will revert all files.
See the link for the Man Page description of it.
hg update is usually used to refresh your working directory after you pull from a different repo or swap branches. hg up myawesomebranch. It also can be used to revert to a specific version. hg up -r 12.
An alternative solution to hg revert is hg update -C. You can discard your local changes and update to some revision using this single command.
I usually prefer typing hg up -C because it's shorter than hg revert --all --no-backup :)
hg revert is your friend:
hg revert --all
hg update merges your changes to your current working copy with the target revision. Merging the latest revision with your changed files (=current working copy) results in the same changes that you already have, i.e., it does nothing :-)
If you want to read up on Mercurial, I'd recommend the very awesome tutorial Hg Init.
hg revert --all
and then
hg pull -u
works for me

Mercurial: pull changes from unversioned copy

I am currently maintaining a Mercurial repository of the project I am working on.
The rest of the team, however, doesn't.
There is a "good" (unversioned) copy of the code base that I can access by SSH. What I would like to do is be able to do something like an hg pull from that good copy into my master repository whenever it gets updated.
As far as I can tell, there's no obvious way to do this, as hg pull requires you have a source hg repository.
I suppose I could use a utility like rsync to update my repository, then commit, but I was wondering:
Is there was an easier/less contrived way to do this?
In short: not that I know of.
If I were in your position, though, I'd keep the "central" code in one branch, do my dev in another branch, then have scripts which would push/pull as appropriate.
For example, the pull script would:
hg co central (making sure to abort if the working copy had uncommitted changes)
rsync ssh://central/repo
hg ci -m "snapshot of central on $(date)"
The push script would then be something like:
./pull
hg co central
hg merge <your working branch>
... test, fix any conflicts ...
rsync . ssh://central/repo
Finally, I would apply clue stick liberally until the rest of the team is on board :) (although you probably knew that already).

Fastest way to "reset" Mercurial repository to Version X (without cloning)

Let's say I clone a remote Mercurial repository (over the local network or even over the Internet) to try something out.
I work in my clone, make a few commits...and then I realize that my changes don't make sense and I have to start over again.
So I want to have a "fresh" clone again, from the same source repository.
Basically, I want to "reset" my local repo to the point before I started experimenting.
What's the best / fastest way to do this?
The simplest way would be to just make a new clone, but then HG copies the whole repo and the whole history over the network again.
If the repo is really big, this will take some time and/or block the network.
I tried to make a new clone into the same folder (hoping that HG would recognize this and update only the files which have changed and the history) but that seems to copy the whole repo as well.
I could "hg rollback", but this rollbacks only the last commit. If I made several commits, I can only undo the last one. So I can't reset the repo to the point before I started committing.
Any ideas?
Is there really no other way than to clone the whole thing again?
(note: a solution with TortoiseHg would be nice...I prefer this over the command line)
You'll end us using hg strip as gizmo suggests, but the traditional way to do this would be to clone again -- not from the remote repo, but from your own local repo. For example, if you checkout is 'repository' and you've added changesets 99 and 100 that you don't like you'd do:
cd ..
hg clone -r 98 respository repository-scrubbed
mv repository respository-with-crap-I-do-not-want
mv repository-scrubbed repository
That should be near instantaneous.
If you enable the Strip Extension, you can use the "hg strip" command that will remove the history you don't want anymore.
More information is available on the Strip command wiki page.
hg update -r <changeset number>
eg hg update -r 1 for the second version. You can use hg log to see what version you want