1

The git repository of my current project, containing source code and image files, measures around 1.2 gigabytes. But the the actual files of all branches are only around 205 megabytes in size.

I am a beginner with git and I guess that the huge repository size is caused by moving the image files around in the repository. Since git doesn't catch moved files, it stores the image at its old location in the history along with the image at its new location. I am not sure if that could cause such a big overhead.

Anyway, how can I reduce the repository size without loosing the history of source code files? It is acceptable for me to loose the history of image files.

Mus
  • 7,290
  • 24
  • 86
  • 130
danijar
  • 32,406
  • 45
  • 166
  • 297

1 Answers1

2

Git does not store extra copies of files that are moved or copied. If the content is the same, the only thing that git stores is the new tree structure(s).

Details on the Git object model: http://git-scm.com/book/en/Git-Internals-Git-Objects

git gc is the common way to do regular house-keeping on a repository, give it a shot and see if your repository shrinks.

If that doesn't do it (sometimes git gc will choke, particularly on repositories with a lot of binary data), try using git repack. It'll often take quite a while, but it should shrink the repository, if at all possible. Try this:

git repack -adf --window=250 --depth=250 --window-memory=1024M

Note the --window-memory option; if your machine has enough memory you might just get away without using this option, but if not it should prevent git repack from failing from running out of memory. In my experience, setting it to half or less of the available memory usually works fine.

jsageryd
  • 4,234
  • 21
  • 34
  • The `git gc` command freed 400 megabytes at least. Using the other command I ran out of memory with either `2048M` or `1024M` but I have 4GB of ram installed on my machine. There are no other resource critical tasks running. Do you have any idea? – danijar Mar 18 '13 at 17:50
  • It seems `git gc` had good effect. Perhaps `git repack` won't do much better. But you can try experimenting with the values and see. Lower `--window-memory` even more; if that still fails, try lowering the other options. – jsageryd Mar 19 '13 at 08:31
  • You were right, with lover `window` and `depth` values it proceeded but without a noticeable gain. – danijar Mar 19 '13 at 10:04