7

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.

Now I have 200+ MB of data I don't need taking up space on my hard disk, even after I've deleted the files. This isn't really a problem, but the bitbucket repository I sync to only gives me 1 GB of space, which I will need for my data.

Stupidly I then deleted the files and committed again, so I can't just use rollback as described in https://stackoverflow.com/a/3290523/961959 without creating a new repository and having to reset up everything with bitbucket.

Is there a way I can fix this, so I don't waste a quarter of my repository space? Can I rollback the last 2 commits I did?

3 Answers 3

5

You can:

  1. Use hg strip to remove the changeset where you've added the files and all of its descendants (note that this will obliterate them completely, so only do it if these files are the only thing committed during this time).
  2. Import those changesets to MQ and edit them.
  3. Use hg convert from Mercurial to Mercurial with --filemap option.
  4. Clone your repository up to faulty changeset and push from this one instead, as described in FAQ.
3
  • Can you explain set 2 for me? Thanks.
    – Canageek
    Dec 11, 2011 at 20:37
  • 1
    @Canageek: It'd be lengthy. Look up MQ tutorial on Mercurial wiki. Dec 11, 2011 at 20:38
  • @Cat Plus Plus: +1 to your answer (and to OP's question). I was going to suggest option 4: clone/push the clone/delete the original repo. Dec 12, 2011 at 13:08
4

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
8
  • Would there be a problem with just rolling back B and C, then recommitting everything?
    – Canageek
    Dec 11, 2011 at 22:19
  • @Canageek Alas, you can only rollback one most recent operation in Mercurial.
    – Helgi
    Dec 11, 2011 at 22:23
  • To clarify, I use the hash for B and C right: So something like 8d2c0cb0012a
    – Canageek
    Dec 12, 2011 at 16:36
  • First problem: I tried your solution: "hg strip 8d2c0cb0012a" gets the response "hg: unknown command 'strip' Mercurial Distributed SCM" and then a list of basic commands. I take it I've installed a lightweight version or somesuch? I've got Mercurial Distributed SCM <version 1.9.2>
    – Canageek
    Dec 12, 2011 at 17:26
  • @Canageek Have you enabled the MQ extension?
    – Helgi
    Dec 12, 2011 at 18:50
0

In case the changes are already pushed to BitBucket, it does offer an option to strip changesets from the server. After performing the strip locally, you should access the url:

https://bitbucket.org/<user>/<repo>/admin/strip

It'll offer an option to strip all changes following a specific commit.

NOTE: There used to be a link to reach that URL in the repo config menu. Now the only way to access it seems to be typing it directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.