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

前端 未结 5 725
傲寒
傲寒 2020-12-08 13:29

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. I

5条回答
  •  被撕碎了的回忆
    2020-12-08 14:06

    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:

    1. Enable the MQ extension in your .hgrc:

      [extensions]
      mq =
      
    2. Pull recent changes from upstream.

      hg pull
      
    3. Import everything from the file addition onward into MQ:

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

      hg qpush 1301.diff
      hg forget path/to/badfile.cfg
      hg qrefresh
      
    5. Convert the patches into new Mercurial revisions.

      hg qpush -a
      hg qfinish -a
      
    6. Push the new revisions upstream.

      hg push -f
      
    7. 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.

提交回复
热议问题