Is there a way to delete history for a single file in Mercurial?

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

We have a file that has been added to the Mercurial repository with sensitive information. Is there a way to delete this file along with the change history without deleting the entire repo?

+46
version-control dvcs mercurial
Jun 22 '09 at 21:24
source share
5 answers

No, you can’t. Read the changes that should never have been in the red book section about her; and in particular, what about sensitive changes that come out of the subsection that contains this paragraph:

Mercurial also does not provide a way to completely make a file or a set of changes disappear from history, because there is in no way disappearance; someone could easily change their copy of Mercurial to ignore such directives. Moreover, even if Mercurial provided such an ability, someone who just didn’t pull out the “make this file missing” changeet would not be affected by this, nor would web scanners visiting the wrong time, disk backup or other mechanisms. Indeed, no common version control system can make data disappear reliably. Giving the illusion of such control could easily give a false sense of security and worse than not giving it at all.

The usual way to return committed changes is supported by mercurial using the backout (again, Mercurial book: dedicated to making perfect changes ) but the information doesn’t disappear from the repository: since you never know who cloned your repository exactly, this would give a false sense of security, as described above.

+22
Jun 23 '09 at 3:07
source share

It is true that you cannot easily delete a specific file from Mercurial in the sense that this will cause all change set identifiers to fail in your repository. When you change change set identifiers, everyone must re-clone the repository. See the edit history wiki page for information on the effects of changing a story in Mercurial.

If this is normal for you (internal repository in the company), take a look at convert extension . It can perform hg → hg conversions and has an argument - filemap , which can be used, in particular, to exclude files.

+58
Jun 23 '09 at 9:09
source share

This is possible locally, but not globally, and it changes the identifier of each commit after the point at which the file was added. For the changes to take effect, you will need access to each copy of the repository, especially those that are popped or popped out.

However, I followed the Edit History described on the Mercurial wiki to remove the file from one of my repositories. In this sequence, it is assumed that in the 1301: 5200a5a10d8b edition, the path/to/badfile.cfg file is added, which was not changed in any subsequent revision:

  • Include the MQ extension in .hgrc :

     [extensions] mq = 
  • Check out the latest changes from the upstream.

     hg pull 
  • Import all of the add file into MQ:

     hg qimport -r 1301:tip hg qpop -a 
  • Remove the file from the command that added it.

     hg qpush 1301.diff hg forget path/to/badfile.cfg hg qrefresh 
  • Convert fixes to newer versions of Mercurial.

     hg qpush -a hg qfinish -a 
  • Click new versions up.

     hg push -f 
  • In the upstream repository and each individual copy, delete the old versions.

     hg strip 5200a5a10d8b 

Warning This step can ruin the work if you are not careful. If someone has done something since the last time you pulled out of the upstream, you will have to reinstall this work before removing. Unfortunately, the rebase extension rebase not useful here; you will have to use MQ again, converting the new commits into the patches that you apply for the new tip.

Good luck.

+7
Nov 22 2018-11-11T00:
source share

This can be done in less than 10 minutes. in one repository, although there are consequences.

How: use hg convert as described in this excellent guide . Basically, you "convert" an Hg repo to a new Hg repo, but you can specify a list of files to exclude during conversion. This is a snippet of key steps:

 Make sure all your teammates have pushed their local changes to the central repo (if any) Backup your repository Create a "map.txt" file: # this filemap is used to exclude specific files exclude "subdir/filename1.ext" exclude "subdir/filename2.ext" exclude "subdir2" Run this command: hg convert --filemap map.txt c:/oldrepo c:/newrepo NOTE: You have to use "forward-slash" in paths, even on windows. Wait and be patient Now you have a new repo at c:\newrepo but without the files 

As for the consequences ...

  • all change set identifiers after the files you want to exclude have been added will be different.
  • The new “clean” primary repository must be manually placed instead of the existing one.
  • all team members will have to create new clones of the main repo
  • any other services that integrate with Hg may require attention (for example, an error tracker, code verification system, etc.).
+4
Sep 04 '15 at 9:52
source share

hg graft then hg strip

-2
Jun 23 '09 at 6:30
source share



All Articles