0

I am using Git on Windows 10, along with Netbeans 8.1, also testing Smartgit. Once the repository was created, I have accidentally committed binaries and other-than-source files and the repository size whopped to 680MB! Although I have created a .gitignore file and manually instructed NB what folders to be ignored, I can't find a way to recover the wasted space in the repository.

I have read those resources, however I have no bash terminal on Windows and none of the suggestions seem to help:

  1. Reduce git repository size
  2. How to reduce size of git repository after accidental push of large file size?
  3. how to reduce git repository size

One important aspect is that the binaries I want to exclude are still in the working tree (cannot remove them for functional reasons) however they should be ignored by Git and removed from the repo.

What can I try?

Community
  • 1
  • 1
Riccardo
  • 2,054
  • 6
  • 33
  • 51

1 Answers1

0

Well, .gitignore only ignores certain files located in the work tree; it certainly not does anything to whatever had already been committed and is thus stored in the repository's object store. In other words, .gitignore is sort-of a filter helping you visually weed out irrelevant stuff when you study the output of git status, and it also makes "globbing" (or "wildcard") arguments to certain Git commands ignore such irrelevant files as well, so that, for instance, git add . won't add whatever is .gitignored unless you explicitly tell it to consider them.

As you can see, your problem can only be solved by actually modifying parts of the history already recorded: that is, you need to rewrite every commit containing these big files so that the new commit created in place of the original one does not reference them. After that, when all references to that old original history were deleted, the objects in the repository's storage which hold those files become unreferenced (and hence considered garbage), and the next run of git gc will actually nuke them from the repository.

The standard way to deal with this is the git filter-branch command. Specifically, you'd need to use its --index-filter command-line option and an appropriate script to filter it. Consider starting with the "EXAMPLES" section of its manual page to get an overview.

This command is somewhat tricky to use (but HOWTOs on how to use are present in abundance in the internets) so if you're not too much into hard-core Git commands, you might consider a more general-purpose custom tool, The BFG Repo Cleaner for your one-off gig.

kostix
  • 51,517
  • 14
  • 93
  • 176