1

I am facing a very strange issue which I had never faced in the past .

I moved lots of images and pdfs and other documents to my project git repository the repository size was increased to 290 MB

Later realized and moved all those stuff to an amazon s3 server and deleted them from repo since I don't need to keep there versions .

Now my code base size has decreased to 8 MB . I continued my work with the codebase by doing new commits .

I recently wants to move them to new server . I now realized that the size of my repository when I new ly clone is more than 230 MB .

After clone If I check the .git folder its size was 200 MB .

This clearly shows that I deleted those images long back and committed to the repo but its still there in the history .

How can I solve this issue .

The issue is how to remove things which we don't need permanently from git repository . As in my case I have already done lot of changes to codebase after deleting those binary stuff, but still the things exists in history .

may be I might have done

git rm *.something && 
git rm --cached filenames

But I just manually deleted them from the repo and did a git commit and pushed to remote repository which was a blunder how can I solve this strange problem ? .

Is there a way so that I could reduce the size of my .git folder

Please suggest ,

Thanks in advance

Aravind.HU
  • 9,194
  • 5
  • 38
  • 50
  • possible duplicate of [Completely remove files from Git repo and remote on GitHub](http://stackoverflow.com/questions/5563564/completely-remove-files-from-git-repo-and-remote-on-github) – reto Jun 11 '14 at 13:55
  • @reto but my problem is the size of .gitfolder – Aravind.HU Jun 11 '14 at 14:06
  • @reto how can I remove them now – Aravind.HU Jun 11 '14 at 14:06
  • There's also [the BFG](http://rtyley.github.io/bfg-repo-cleaner/). *Much* faster by all accounts, and it's actually recommended in the v1.9.0 and later filter-branch docs. Everybody working off your repo is going to have to refetch to get the new history and rebase all their work on top of it, and eventually prune, but that's the only real downside. – jthill Jun 11 '14 at 14:14
  • 1
    @aravind.udayashankara That *is* your problem. Removing the files doesn't remove them from the history of the repo. Otherwise, how could you checkout a previous commit which referenced a file that was removed? You need to remove the files from the entire history of the repository, as the linked answer explains. – user229044 Jun 11 '14 at 14:15

2 Answers2

4

This worked for me

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch folder/" HEAD 

To clean my local repo cache

rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune

After doing it your local branch will be diverged . IF you run git status it shows you are staying behind from the origin .

So just take a git pull to merge from remote and do a push so that repo size gets reduced .

References : -

Clear historical files/folders from git repository

The SO posting

Completely remove files from Git repo and remote on GitHub

Assisted me to get this link , The title of the question mislead-ed me in the beginning So I am posting the solution since this scenario is little specific and might help others who are facing the same problem .

Community
  • 1
  • 1
Aravind.HU
  • 9,194
  • 5
  • 38
  • 50
1

Use:

git gc --aggressive

To clean up old files in your repo.

James Wong
  • 4,529
  • 4
  • 48
  • 65
Anubian Noob
  • 13,426
  • 6
  • 53
  • 75