3

Accidently I checked-in 5GB around of files to Mercurial. Our Build server started failing during cloning of repo. So we reverted the checked- in files by using Remove command. But .hg/store/data is still containing those files. And it's size is over 5GB. We have searched over internet and found few methods, like: hg convert. But hg convert is creating new repo which is not desired in our case. Also we cannot extend the Timeout period of our build server.

How could we remove the bad check-in completely without making it to store in .hg/store/data? Or How could we reduce the size of .hg/store/data?

Sumit Sood
  • 193
  • 2
  • 7
  • How is the repository hosted? Where is your server? Do you use bitbucket or some cloud solution or do you host it yourself? – Lasse V. Karlsen Aug 29 '16 at 06:02
  • Hi Lasse. We use Bitbucket to host our repository – Sumit Sood Aug 29 '16 at 06:08
  • 1
    Then what you want to do is strip those changesets. Under settings you can do this. Note that **every** clone that already contain the bad changeset will have to be scrapped and recloned. Depending on your build server it may need to be refreshed as well if it keeps a cache of changesets ready to come in. **Also note that any changesets following the bad commit will be stripped** so you need to graft those onto the branch in a local clone and clean up. I can post a better answer tonight but unfortunately not now. – Lasse V. Karlsen Aug 29 '16 at 06:20
  • http://stackoverflow.com/questions/28735889/how-to-delete-remote-commit-from-bitbucket-mercurial-repository and http://stackoverflow.com/questions/9627964/how-can-i-completely-replace-a-bitbucket-repository-with-another-repository explain how to strip changesets from a Bitbucket mercurial repository – Leon Aug 29 '16 at 06:25

2 Answers2

2

Here's what you need to do: You need to strip those changesets.

Since your repository is hosted on Bitbucket, you do not have direct access to the files so you need to use what the website provides.

In your repository project, under settings, there is a section for stripping out changesets.

Note that this will also remove any changesets that were committed on top of the bad changeset. We will deal with this.

I will stress this:

  1. Make
  2. Sure
  3. You
  4. Have
  5. Backups!

Here are the steps

Important: If any developer on your team has anything pending locally, like changesets not yet having been pushed to bitbucket, but they have cloned the bad changeset from bitbucket, then you need to do more grafting, be sure you understand everything that needs to be done before attempting this.

  1. Make sure you have a good backup and a local clone of your repository, this is paramount I (or Stack Overflow) is not responsible if you end up losing changesets you want to keep in this process. Pay especially head to the warning above about not-pushed-changesets that other developers might have.
  2. In the local clone, first graft any and all changesets that were committed on top of the bad changeset onto the changeset directly preceeding it.

    ie. if the history looks like this:

    1---2---3---BAD---5---6---7
    

    You want to graft 5-7 on top of 3 so that you afterwards have this history:

    1---2---3---BAD---5---6---7
             \
              +--5---6---7
    
  3. Then strip the bad changeset (and everything that follows it) by using this command:

    hg strip BAD
    
    `BAD` here is the number or hash of the bad changeset
    
  4. Verify that everything looks good locally, then head on to bitbucket.org
  5. Find your repository, go into Settings and find the strip changesets section
  6. Input the hash of the bad changeset and ask bitbucket to strip it out
  7. Afterwards, push from your local clone to bring the changesets you grafted back into bitbucket
  8. Important: Now you need to get everyone that has already cloned from bitbucket and gotten the bad changeset need to scrap their local clone and reclone. This will bring down a fresh copy of the repository, without the bad changeset.
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • Hi Lasse. Thanks for providing what is required. I would like to know how to graft the new changeset after Bad changeset. As you said "You want to graft 5-7 on top of 3 so that you afterwards have this history:". Please provide hg command for the same. – Sumit Sood Aug 29 '16 at 06:50
  • You can't, you must graft them before because the strip command will remove them. If you do that then it is too late. – Lasse V. Karlsen Aug 29 '16 at 06:51
  • I would like to know how to graft the new changeset after Bad changeset. As you said "You want to graft 5-7 on top of 3 so that you afterwards have this history:". Please provide hg command for the same. – Sumit Sood Aug 29 '16 at 06:59
  • I would recommend you use a visual tool but using the command line you would first update to the changeset prior to the bad one, then issue this type of command: `hg graft -r 20:30' where 20 and 30 are the revision numbers or hashes of the first and last good changeset that follows the bad one. You do not want to include the changeset where you tried to remove the files. – Lasse V. Karlsen Aug 29 '16 at 08:04
  • Thanks for reply :) – Sumit Sood Aug 29 '16 at 08:41
1

The -r option of hg clone allows creating a repository without changesets after a particular revision.

So you can do the following (assuming LAST_GOOD_CHANGESET is the changeset just before your wrong commit):

hg clone -r LAST_GOOD_CHANGESET repo repo.1
mv repo repo.bak
mv repo.1 repo

Note however that this will drop all commits after your wrong commit, so you will have to replay the important ones (i.e. excluding those that were made in attempts to fix the mistake).

Besides, if you have branches, you must list them as additional -r arguments to hg clone, otherwise they will be dropped from the cleaned up repository too.

Leon
  • 31,443
  • 4
  • 72
  • 97
  • Hi Leon. Our build server is automatically cloning the repository and is not under our control. We just want to remove those bad files from .hg/store/data – Sumit Sood Aug 29 '16 at 06:10
  • @SumitSood Is the source repository (from where the build server clones) under your control? I meant that you perform the suggested operations on your source repository. – Leon Aug 29 '16 at 06:15