Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep a Mercurial repository small?

Tags:

mercurial

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?

like image 671
Dimitri C. Avatar asked Feb 27 '23 15:02

Dimitri C.


2 Answers

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.
like image 175
Ry4an Brase Avatar answered Mar 06 '23 18:03

Ry4an Brase


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.

like image 43
catchmeifyoutry Avatar answered Mar 06 '23 19:03

catchmeifyoutry