简体   繁体   中英

How do I do a pristine checkout with mercurial?

How do I get the working directory state back to what it would have been from a new clone of the repository (Obviously I could clone my repository, but that seems a bit savage.)

With git I'd do:

git clean -xdn (dry-run, to see what I'm about to destroy)

git clean -xdf (force, to actually do it)

And I'm assuming that there's probably a subtly different mercurial equivalent, but I can't find it.

Your git clean command remove untracked files from the working tree, including ignored files. The equivalent Mercurial command is provided by the standard purge extension :

hg clean --all --print

Remove the --print to actually delete the files, remove --all to only delete untracked files and leave ignored files behind.

If you also want to discard local changesets that haven't been pushed, ie, the equivalent of

git reset --hard origin/master

then you need to enable the mq extension and run

hg strip "outgoing()"

Your local clone will now look just like when you first cloned it.

(Yes, we also have sharp tools in our toolbox, but they're hidden away until you decide to use them.)

Use update with -C or --clean to update to a revision and discard any local uncommitted changes.

hg status   (to see what you're about to destroy)
hg update <revision> -C

If you don't want to modify the parent revision, you can also use revert :

hg revert -anC  (dry run)
hg revert -aC  (all files, no backups)

Use hg help update or hg help revert for documentation on options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM