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?
CodePudding user response:
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
- Checkout
git checkout --orphan latest_branch
- Add all the files
git add -A
- Commit the changes
git commit -am "commit message"
- Delete the branch
git branch -D main
- Rename the current branch to main
git branch -m main
- 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)
CodePudding user response:
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:
- https://docs.gitlab.com/ee/topics/git/lfs/migrate_to_git_lfs.html
- https://notiz.dev/blog/migrate-git-repo-to-git-lfs
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
