0

So I'm doing a project in Unity and I was curious why my project size is so large (200Gb), then I realized there is a hidden .git folder which size is 80Gb. Someone told me to compress my database, that would free up space, so I went to Git GUI and pressed on compressed and it consumed all of my free space in my disk, the command didn't even finished.

What can I do now with 300mb free of space to clear the .git folder?

matmalm
  • 1
  • 1
  • 2
  • Have you tried [How can I clean up my .git folder?](https://stackoverflow.com/questions/5277467/how-can-i-clean-my-git-folder-cleaned-up-my-project-directory-but-git-is-sti) .. still this sounds way to huge for a git project even without those 80GB .. are you using Git LFS? Maybe you can also prune old LFS files – derHugo Jan 18 '22 at 00:19

2 Answers2

1

then I realized there is a hidden .git folder which size is 80Gb

If your .git folder is that big and that you are doing Unity development, I really hope that you are using git-lfs.

Otherwise you did a big mistake and you will have to fix that (and it's much more complicated if you don't have free space anymore so I won't answer here)

If you are using git-lfs, you can cleanup objects not used anymore with the command: git lfs prune

Only after that and if it made some free spaces, then you could do a git gc

So I went to Git GUI and pressed on compressed and it consumed all of my free space in my disk, the command didn't even finished.

If it behave like that and failed to compress the git object, that probably means that you didn't enabled git-lfs and so git has difficulties to compress your big binaries assets so you will have to enable it and convert your whole git history to use it. But before ensure that the git hosting you are using is supporting it...

For your migration, things like that could help:

And I'm not sure it could be done when your disk is full. So maybe you will have to make free space or copy your repository elsewhere and do the work from there (it still a good idea to do a copy as a backup before starting to do these things).

Buy an external hard drive if needed...

Unity with Git: https://thoughtbot.com/blog/how-to-git-with-unity

Philippe
  • 28,207
  • 6
  • 54
  • 78
0

Git history can take up a lot of space, even if big files aren't on the latest branch.

You can remove all Git history for the repo and have the current state become the initial state:

As seen from: https://stackoverflow.com/a/26000395

  1. Checkout
  • git checkout --orphan latest_branch
  1. Add all the files
  • git add -A
  1. Commit the changes
  • git commit -am "commit message"
  1. Delete the branch
  • git branch -D main
  1. Rename the current branch to main
  • git branch -m main
  1. Finally, force update your repository
  • git push -f origin main

That will free up a lot of space in your .git folder.

Also see: Make the current commit the only (initial) commit in a Git repository?

(This is essentially the same solution I posted in https://stackoverflow.com/a/70742570/7058266)

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • Yeah .. don't do that ^^ why would you want to complete delete all history of a repo ... What you rather want to do in most cases is simply not download all history but limit it to the last x commits. What you do is more for cleaning up server side – derHugo Jan 18 '22 at 00:46
  • It's one possible solution based on what the user wants. As seen from the number of upvotes on https://stackoverflow.com/a/9683337/7058266, some people prefer to remove all Git history and clean up the maximum possible space. – Michael Mintz Jan 18 '22 at 00:52
  • If this is already posted in a different question then don't cross duplicate post the answer but rather post the link as a comment. – derHugo Jan 18 '22 at 07:04