Dimitri C.
Dimitri C.

Reputation: 22496

How to keep a Mercurial repository small?

My central repository is stored on an 8GB USB stick. I accidentally committed some big files, so the repository doesn't fit on the stick anymore. Is there a way to correct this situation?

Upvotes: 4

Views: 730

Answers (3)

Ry4an Brase
Ry4an Brase

Reputation: 78350

I voted up catchyifyoutry's answer since he's got the steps you'll probably use, but here's a handy list.

First, though, a reminder. If you've already pushed this repository somewhere semi-public, and people have pulled the repository, then none of the tips below will work. When next they push and you pull you'll get the original changesets back in their unmodified form. Your only recourse is to talk to each person who has a clone and ask them to delete it and re-clone. That said, on to the list:

Ways to obliterate files you committed on accident

  • If you've not yet pulled or committed anything else: hg rollback will act as one level undo
  • If you're willing to throw away the last N revisions: hg clone -r -N repo-with-too-much repo-with-N-fewer changesets # example: hg clone -r -2 big-repo small-repo
  • If your change was too long ago for either of those to be okay: hg convert --filemap myfilemap.txt too-big-repo new-repo

In that last case myfilemap.txt has in it:

exclude path/to/file/to/remove

Notes:

  • the clone -r case technically asks for the minimal clone that could include revision tip-N, which if you have a branchy repo. Additionall pull -r lines (one per head) will be necessary to pull over other non-linear history.
  • with the hg convert solution the hashcode of every modified changeset and all of their descendants will be modified.

Upvotes: 6

catchmeifyoutry
catchmeifyoutry

Reputation: 7389

You can rollback the last commit with the big files, if the commit really accidental. See

hg help rollback

Of course, this doesn't work if you committed other important stuff on top in the meantime. Another way would be to use strip to remove the whole branch containing the big files.

Be careful, before you perform any of these operations, make sure you understand what you're doing! Test the commands first on a test repository or clone.

Upvotes: 4

m_pGladiator
m_pGladiator

Reputation: 8620

Never ever store such important thing as a code repository on a USB stick. That's an invitation to loose all your code very soon! Buy an external HDD with enough space and at least 2 separate disks inside, which you can mirror. Store it permanently somewhere and don't carry it around. If you need access from other place - use a secure internet connection to access your HDD remotely.

Upvotes: -2

Related Questions