Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I clean my .git folder? Cleaned up my project directory, but .git is still massive

Tags:

git

The .git/objects in my rails project directory is still massive, after deleting hundreds of Megabytes of accidentally generated garbage.

I have tried git add -A, as well as other commands to update the index and remove nonexistent files. I gather, perhaps incorrectly, that the files with two character names in the directory are blobs. I have tried rolling back to previous commits, but no luck.

What can I do to clean this directory?

like image 336
light24bulbs Avatar asked Mar 11 '11 19:03

light24bulbs


People also ask

Does deleting the .git folder delete the repo?

Deleting the . git folder does not delete the other files in that folder which is part of the git repository. However, the folder will no longer be under versioning control.

Why is there a .git folder in my project how did it get there why is it hidden and what does it do?

The . git folder is hidden to prevent accidental deletion or modification of the folder. The version history of the code base will be lost if this folder is deleted. This means, we will not be able to rollback changes made to the code in future.

Is .git folder tracked?

No, there isn't. But you can store in git a text files with the 2 or 3 commands you use to reconfigure each repository. You can make it a .


2 Answers

  • If you added the files and then removed them, the blobs still exist but are dangling. git fsck will list unreachable blobs, and git prune will delete them.

  • If you added the files, committed them, and then rolled back with git reset --hard HEAD^, they’re stuck a little deeper. git fsck will not list any dangling commits or blobs, because your branch’s reflog is holding onto them. Here’s one way to ensure that only objects which are in your history proper will remain:

    git reflog expire --expire=now --all git repack -ad  # Remove dangling objects from packfiles git prune       # Remove dangling loose objects 
  • Another way is also to clone the repository, as that will only carry the objects which are reachable. However, if the dangling objects got packed (and if you performed many operations, git may well have packed automatically), then a local clone will carry the entire packfile:

    git clone foo bar                 # bad git clone --no-hardlinks foo bar  # also bad 

    You must specify a protocol to force git to compute a new pack:

    git clone file://foo bar  # good 
like image 60
Josh Lee Avatar answered Oct 04 '22 12:10

Josh Lee


Have you tried the git gc command?

like image 42
ryanprayogo Avatar answered Oct 04 '22 11:10

ryanprayogo