Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trimming huge git repository size

Tags:

git

I'm not that well versed in using git, but have been using Xcode and a local repository on my machine.

All seemed well, until today when I was trying to free up some space on my HDD. I noticed that in my repository's .git directory there were a couple of large files (6.3 and 1.4 GB).

Screenshot

I have no idea what these files are for, and a Google search has revealed little about them.

Because I have a Macbook Air, storage space is at a premium. I would like to find a way to compress or remove these large files, but I don't want to corrupt git's version history.

like image 512
Hubert Kunnemeyer Avatar asked Dec 22 '12 01:12

Hubert Kunnemeyer


3 Answers

The screenshot shows two small index files and two huge packs. So I believe you have commited a few huge files in Git.

To find top 10 largest blobs, you can use the following command:

git verify-pack -v .git/objects/pack/<pack>.idx | sort -k 3 -n | tail -10

It should produce: SHA-1 blob size ... Then you can look at this object using its SHA-1:

git show <SHA-1>

or you can learn its name:

git rev-list --objects --all | grep <SHA-1>
like image 119
user1922076 Avatar answered Oct 19 '22 23:10

user1922076


The Pro Git book has an excellent section on what to do when you've accidentally committed something huge into your repository:

http://git-scm.com/book/en/Git-Internals-Maintenance-and-Data-Recovery

like image 45
matt Avatar answered Oct 19 '22 23:10

matt


Pack files are bundled history files that git uses.

If you want to clean up some space, do the following:

  • git branch to list branches, and git branch -d <old branch> to delete old branches (do this first)
  • git gc will clean and compact the repo
  • git prune will remove extra files (like the reflog, which keeps track of all commits, even deleted ones)
  • git gc --prune=now will gc and prune in one command

After doing this, I'd be interested to see how much space you save. If your repo's history is really 7 GB, you'd probably be better off in moving it to an external HDD.

like image 42
neersighted Avatar answered Oct 19 '22 23:10

neersighted