tags:

views:

417

answers:

3

I think I already know the answer to this but thought I would ask anyway:

We have a file that got added to a Mercurial repository with sensitive information in it. Is there anyway to remove that file along with its change history without removing the whole repo?

+5  A: 

No, you can't. Read the changes that should have never been section of the mercurial red book about it; and particularly the what about sensitive changes that escape subsection, which contains this paragraph:

Mercurial also does not provide a way to make a file or changeset completely disappear from history, because there is no way to enforce its disappearance; someone could easily modify their copy of Mercurial to ignore such directives. In addition, even if Mercurial provided such a capability, someone who simply hadn't pulled a “make this file disappear” changeset wouldn't be affected by it, nor would web crawlers visiting at the wrong time, disk backups, or other mechanisms. Indeed, no distributed revision control system can make data reliably vanish. Providing the illusion of such control could easily give a false sense of security, and be worse than not providing it at all.

The usual way to revert committed changes is supported by mercurial through the backout command (again, mercurial book: dealing with committed changes) but the information does not disappear from the repository: since you never know who exactly cloned your repository, that would give a false sense of security, as explained above.

NicDumZ
A: 

hg transplant, then hg strip

evilbloodydemon
The file goes through almost the entire change history. Can you expand on how you could use the commands above to purge the file history from the repo while leaving the change history for the other files intact?
Matt Spradley
You cannot use transplant to remove a single file from a changeset -- transplant only know how to move whole changesets from one branch or repository to another (it's like hg export | hg import). See my answer about the convert extension.
Martin Geisler
+7  A: 

It is correct that you cannot easily remove a particular file from Mercurial in the sense that doing so will disrupt all the changeset IDs in your repository. When you change the changeset IDs, everybody has to re-clone the repository. See the Wiki page about editing history for information about the consequences of modifying the history in Mercurial.

If that is okay to you (internal repository in a company), then take a look at the convert extension. It can do hg → hg conversions and has a --filemap argument which can be used to exclude files, among other things.

Martin Geisler