It is possible locally, but not globally, and it changes the ID of each commit after the point at which the file was added. In order for the change to stick, you'll need access to every single copy of the repository, particularly the ones that get pulled or pushed from.
That said, I have followed the Editing History sequence described on the Mercurial wiki to remove a file from one of my repositories. This sequence assumes that revision 1301:5200a5a10d8b added the file path/to/badfile.cfg
, which was not changed in any subsequent revision:
Enable the MQ extension in your .hgrc
:
[extensions]
mq =
Pull recent changes from upstream.
hg pull
Import everything from the file addition onward into MQ:
hg qimport -r 1301:tip
hg qpop -a
Remove the file from the commit that added it.
hg qpush 1301.diff
hg forget path/to/badfile.cfg
hg qrefresh
Convert the patches into new Mercurial revisions.
hg qpush -a
hg qfinish -a
Push the new revisions upstream.
hg push -f
On the upstream repository and every single other copy, remove the old revisions.
hg strip 5200a5a10d8b
Warning: This step may destroy work, unless you're careful. If anybody has committed anything since the last time you pulled from upstream, then you'll have to rebase that work before stripping. Unfortunately, the rebase
extension is not helpful here; you'll have to use MQ again, converting the new commits into patches that you apply onto the new tip.
Good luck.