Reputation: 951
I usually use hg strip -k
to remove some changesets before pushing modified code to a remote repository. The problem with this command is that every file that was processed with hg add/remove
is no longer in Added/Removed list
Is there any command that will remove changesets, will keep the changes and will also keep the added/removed files?
Upvotes: 0
Views: 756
Reputation: 6044
Assuming that you do not want to push the latest changeset(s) only: then the best solution is to change their phase from draft or public to secret: hg phase --force --secret --revXXX
where XXX is the earliest of those changesets. This has the advantage that they never leave your local repository but simply won't be pushed until you change their phase back to draft or public.
Generally: public > draft > secret. Public changesets are immutable, drafts are mutable but shared, secret ones mutable and not shared. Drafts might change to public on push when pushed to a publishing repository (default). You might want to read up on phases in general and consider making your default commit phase secret so that you need to change phase for those commits you want to push: Phases
If however you need to remove changesets in the middle of a commit series, just use strip as you are used to. It will put the whole commit into a bundle which can be re-imported into the repository at a later time using hg unbundle BUNDLE_FILENAME
. It won't keep the commits in the repository though, thus remember the filenames or check the bundle filenames contents later using hg incoming BUNDLE_FILENAME
. (Note: should you use the evolve extension you need the --bundle parameter with strip)
If you are uncomfortable with that and rather want 'normal' patch files, use hg export XXX > file_XXX.patch
(XXX being a revision) prior to stripping on the changesets you do not want to share.
Upvotes: 1
Reputation: 8730
The direct answer is to use hg shelve
to temporarily shelve your changes and to use hg unshelve
to restore them afterwards. You may have to enable the built-in shelve extension via an entry in your .hgrc
first, e.g.:
[extensions]
shelve=
Note that the better solution is, as indicated in the other response, to not use hg strip
in the first place, but to use phases to indicate which commits you don't want to push. Using hg strip
here is a bit like using a sledgehammer to crack open an egg. I've still added my response, because there are other uses for hg strip
where having a way to keep the current changes is useful, but the other one is really the "right" response for this use case.
Upvotes: 0