Accidentally committed a large amount of raw data in Mercurial, how do I keep it from overloading my bitbucket repository?

前端 未结 3 1750
南笙
南笙 2021-01-12 09:54

I copied a large amount of data from my labs file server to my laptop, then accidentally committed it to the Mercurial repository I\'m using to back up my thesis.

N

3条回答
  •  情歌与酒
    2021-01-12 10:47

    I'm going to describe what I would do if I wanted to roll back two most recent commits.

    I assume that you haven't pushed to Bitbucked yet. I also assume you have these changesets on top of your DAG:

    o  C: Deleted files FILE1 and FILE2
    |
    o  B: Some nice changes; also added large files FILE1 and FILE2
    |
    o  A: Some good changeset
    

    Here, C should be removed altogether, B should be edited (FILE1 and FILE2 additions should be rolled back), and A and below should be left as they are.

    Caveat: this only works if B and C were not pushed onto Bitbucked (or any other public repo) yet.

    You'll need to enable the MQ extension to do this. To do this, add these lines to the .hg/hgrc file in your repo:

    [extensions]
    mq=
    

    Steps

    First, I strip C:

    $ hg strip C
    

    Now, C is obliterated, and the parent is B. I import B as a Mercurial Queues patch to edit it:

    $ hg qimport -r B -n B.patch
    

    Now I have one patch on top our queue, which was created from B. I remove the big files, and refresh the patch:

    $ hg forget FILE1 FILE2 
    $ hg qrefresh
    

    Now B.patch no longer includes the big files. However, they are still on the disk, albeit not controlled bu Mercurial. I now finish my work with MQ:

    $ hg qfinish -a
    

    Here's what I have at the moment:

    o  B1: Some nice changes, no big files here
    |
    o  A: Some good changeset
    

提交回复
热议问题