Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing unwanted folders from git repo permanently - Repo size not changing

Tags:

git

I have git repo, I have accidentally committed some library files to the git remote repo.

Now it has resulted in increased size of about 6.23 GB. Then I tried deleting the library using the following commands

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch node_modules" -- --all

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

Now the library has been removed from the repository and it is not listed in the repo folders. But still the size of the local repo is bigger as before

One more thing is it takes a lot of time to execute the above commands. I am not sure whether they worked properly

I even did try pushing this to remote repo,

git push --all --force

but that doesnot get pushed successfully,It tries till the last and suddenly comes as the remote repo is not reachable or not responding of that sort

I also tried rewritting the tags

git filter-branch -f \ --index-filter 'git rm -r --cached --ignore-unmatch node_modules' \  --tag-name-filter 'cat' -- --all

I also tried the following to make it work

git config --global pack.windowMemory 0
git config --global pack.packSizeLimit 0
git config --global pack.threads "3"

But whatever I do the size of the repo is still the same

Note: I tried

git fsck --full --unreachable

There are several tags listed that are not reachable

like image 691
keerthee Avatar asked Jul 09 '15 05:07

keerthee


People also ask

How do I permanently delete a directory in Git?

Just run the rm command with the -f and -r switch to recursively remove the . git folder and all of the files and folders it contains.

Does deleting branches reduce repository size?

To reduce the size of your repository in GitLab, you must first remove references to large files from branches, tags, and other internal references (refs) that are automatically created by GitLab.

How do you make a .Git smaller?

remove the file from your project's current file-tree. remove the file from repository history — rewriting Git history, deleting the file from all commits containing it. remove all reflog history that refers to the old commit history. repack the repository, garbage-collecting the now-unused data using git gc.


1 Answers

I mention in Git pull error: unable to create temporary sha1 filename that git gc alone isn't enough.

One combination which should bring down the size of the repo should be:

git gc
git repack -Ad      # kills in-pack garbage
git prune           # kills loose garbage

However, This must follow any cleanup of big file (git filter-branch), and that is only for the local repo.

After pushing (git push --force) to the remote repo, said remote repo won't benefit from the same size reduction. A gc/repack/prune needs to be done on the remote side as well.

And if that remote side is TFS... this isn't easy/possible to do for now.

like image 51
VonC Avatar answered Oct 01 '22 19:10

VonC