1

My repo shoulds be around 2Mo (all my sources and some data) but the whole repo is around 19Mo, actualy the files in .git/objects take ~17Mo...

I read several answers on stackoverflow, about cleaning a git. none of them leads me to clean properly my repo. I know how to delete my src and data, but no clue how delete/clean the objects folder.

I tried to delete the objects folder of my harddrive, but that broke my local repo... (I still have a backup)

The Unholy Metal Machine
  • 1,093
  • 2
  • 17
  • 36

2 Answers2

0

If a git gc --aggressive --prune=now doesn't work (as I mentioned in "Reduce git repository size"), you could simply try and cloning your local repo.

git clone --mirror /path/to/your/current/repo newBarerepo.git

The new clone (a bare repo in newBarerepo.git) should be fairly smaller than your current local (unpacked) repo.
That bare repo is an intermediate step though (since it has no working tree, you cannot work in it directly).

You still need to clone it (again) in order to get back a regular repo (but with a .git folder in it which should be much smaller).

So:

cd /path/to/your/bigBepo
git remote -v # note the url of oyur bitbucket repo
cd ..
git clone --mirror bigRepo BareRepo.git
git clone bareRepo.git newRepo
cd newRepo
git remote set-url origin </url/of/your/bitbucket/repo>

You can check the size of newRepo/.git/ folder, and see if that improved the situation.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • `git gc --aggressive --prune=now` doesn't work. I have a new repo with the right files. But I still trying to don't have to delete my old repo... you know I work for months now on that project... – The Unholy Metal Machine Apr 12 '14 at 20:31
  • @bob-hunterofunicorns I understand. What a `git clone --mirror` gives you? (just to check the size of the bare cloned repo) – VonC Apr 12 '14 at 20:32
  • @bob-hunterofunicorns ok, now clone (classic clone) from that bare repo, and you should be back in business. – VonC Apr 12 '14 at 20:36
  • what do you mean? cd `/path/to/your/current/repo`. then `git clone .git` ? because it works but I still have ~19Mb – The Unholy Metal Machine Apr 12 '14 at 20:43
  • @bob-hunterofunicorns no, I mean clone your new bare repo in another path (or rename your old repo folder, and reuse the same path). – VonC Apr 12 '14 at 20:47
  • I don't understand how this will fix my problem. I think I will send a mail to the technical support team – The Unholy Metal Machine Apr 12 '14 at 20:49
  • @bob-hunterofunicorns your new non-bare repo will contain mostly packed objects, as oppose to your current one: so much smaller. In that new repo, you can change `origin` to point it back to bitbucket: `git remote set-url origin /url/to/your/bitbukcket/repo`. – VonC Apr 12 '14 at 20:51
  • If I understand, your proposition will lead me to use a new repo... I don't plan to do that now. I want to have my old repo cleaned. There is no reason why I could not clean my repo. For me it's sound like an issue from bitbucket, so I will contact their technical support. – The Unholy Metal Machine Apr 12 '14 at 21:15
  • @bob-hunterofunicorns no this will be the same repo, same history, same remote, but smaller. – VonC Apr 12 '14 at 21:30
  • ok, after : `git remote set-url origin /url/to/your/bitbukcket/repo` should I do a `git push origin master` ? – The Unholy Metal Machine Apr 12 '14 at 21:46
  • @bob-hunterofunicorns no, rather a git fetch origin, to get back all your remote tracking branches; then a `git status` to see where you at. – VonC Apr 12 '14 at 22:01
  • I get, `origini/master` is up to date. Untracked files : `newBarerepo.git/` – The Unholy Metal Machine Apr 12 '14 at 22:05
  • If you have cloned `newBarerepo.git/` into a new folder and do operations in that new folder, you shouldn't be seeing anything about `newBarerepo.git/`. The all point of creating a bare repo `newBarerepo.git/` in the first place was to make it small. Then you clone `newBarerepo.git/` into newRepo and change the remote `origin` there, `git fetch`, and `git status`: no more `newBarerepo.git/`: it only sees the bitbucket repo again. – VonC Apr 12 '14 at 22:07
  • Ok, I cd `newBarerepo`. then `git remote set-url .git`, then `fetch origin` and `git status`. I got : `fatal: This operation must be run in a work tree` – The Unholy Metal Machine Apr 12 '14 at 22:15
  • @bob-hunterofunicorns that is what I meant by: "into a new folder", ie one which is *not* `newBarerepo.git/`. 1/ clone --mirror into `newBarerepo.git/`, then 2/ clone newBarerepo.git newFolder, then 3/ `cd newFolder` and change the origin *there*. Not in `newBarerepo.git/`. `newBarerepo.git/` is just a bare repo in order to get back a *small* repo. It is an intermediate step. You then clone that in order to restore a link to your BitBucket repo in that new clone (in `newFolder`, *not* in `newBarerepo.git/` anymore) – VonC Apr 12 '14 at 22:24
  • so in the newFolder, `git remote set-url .git`, then `fetch origin` and `git status`. I got : origin/master is up to date, nothing to commit (working directory clean) – The Unholy Metal Machine Apr 12 '14 at 22:36
  • @bob-hunterofunicorns that is possible, but remember the `git remote set-url` is for setting `origin` back to your bitbucket url repo (instead of `newBarerepo.git/`). `git remote set-url origin /url/of/your/bitbucket/repo`. – VonC Apr 12 '14 at 22:55
  • look, I'm not sure if I did so far is correct or not. could you edit your answer and write all steps ? for now after all I did, I still have 19MB – The Unholy Metal Machine Apr 12 '14 at 23:01
  • @bob-hunterofunicorns but do you have 19Mo in the .git folder only, or wuth the all working tree checked out? – VonC Apr 12 '14 at 23:02
  • on my hardrive, the .git folder is around 600kb. – The Unholy Metal Machine Apr 12 '14 at 23:04
  • @bob-hunterofunicorns looks good, then. I have added the steps in the answer. – VonC Apr 12 '14 at 23:06
  • after all these steps. What I have to do ? – The Unholy Metal Machine Apr 12 '14 at 23:16
  • @bob-hunterofunicorns the idea is to go on working in your newRepo, with a `.git` in it which is much smaller, and with a remote `origin` set back to your bitbucket repo, meaning you can push back to it. – VonC Apr 12 '14 at 23:25
0

The .git/objects directory contains the full history and metadata for your repository. If you have lots of commits (you should), and pretty detailed commit messages (ditto), even the compressed format git uses to store data could get quite large. The repo for my class notes (compressed LaTeX source 3.3MiB, objects 34MiB) is a case in point.

vonbrand
  • 11,412
  • 8
  • 32
  • 52