0

I try to follow the steps here Remove large .pack file created by git however it does not work for me and I am unable to add comments to show my problem I have.

So here is my case and steps:

in my folder .git\objects\pack I have file pack-5b4989a1eaffd866f584f203b9fc4dcf27168727.pack that is 32 MB and I am trying to remove this as this is to be my Template repo and can not be more than 10MB so want to clean it.

I run the following steps:

$ git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch pack-30e62ba457c0929c78bb38eb7bdc1de66730c834.pack' --prune-empty

then

git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --aggressive --prune=now

At the end, my file is still there and was not removed. What I am doing wrong? Appreciate any help

mike
  • 1,233
  • 1
  • 15
  • 36
Michal
  • 19
  • 3
  • 14
  • 1
    First, you don't just want to up and delete the pack file... that's your history, and removing it means you'll likely corrupt your git repo. Second, the steps you point to are about removing files in the working tree that are large. Do you have that issue? Do you have things in history that you don't want to be there? How big is your working tree without the .git folder? You might want to try `git gc` to remove abandoned objects from the pack file. Third, why is the size an issue? – John Szakmeister Aug 28 '20 at 19:40
  • This feels like an "X/Y Problem": your actual problem is that your git repo is too large, and you've identified this file as relevant, then decided that this file is your problem. But the size of the pack file is a _symptom_, not a _cause_: git has created that file because it thinks there is that much data that needs storing. – IMSoP Aug 30 '20 at 07:03
  • @JohnSzakmeister I want to use this repo as Template when starting new repos. There is an error when your template repo is above 10MB. I do not need to keep history for this repo so just want to remove files and there is one pack file 32MB and all the rest is less 1MB. I am just trying to remove large files from my history as I do not need them. However, I do not want to corrupt git repo so I want to do it properly. How can I large files in my host for I can remove large items? – Michal Sep 01 '20 at 07:29
  • @Michal how big is the data for your template repo (not the repo, the files)? And what service are you using that has the 10MB limit? The easiest way I can think of is to run `git clean -fdx` (removes anything that is not versioned), `mv .git .git-backup`, `git init .`, `git add .`, and `git commit`. If you're happy with everything, then you can delete the `.git-backup` folder. Otherwise, you can put the old `.git` back into place and be back to where you were before. Here are some other ways to do it too: https://stackoverflow.com/questions/1657017/how-to-squash-all-git-commits-into-one. – John Szakmeister Sep 01 '20 at 08:49
  • @JohnSzakmeister I am using GitHub and my files for VS are 287 kB all rest 32MB are in .git folder. When you create a new repo on Github and want to use a template it will not allow you to di it if template repo exceeds 10MB which is my case. I have this error: "We're sorry, something went wrong. We were unable to cloneTemplate's contents into Acoustic. The template you used includes files that are larger than 10 megabytes. Please ask Organization to remove those files from the template and try again." – Michal Sep 01 '20 at 09:03
  • I run these commands but now I have .git 31MB and additionally .git-backup with 31MB I expected that by size will decrease... – Michal Sep 01 '20 at 09:14
  • Hmmm... did .git-backup get added to the commit? We definitely don't want that. What does `git log --stat` show? – John Szakmeister Sep 01 '20 at 21:41

1 Answers1

-1

You may need to remove the file from your computers cache.

This can be done using:

git rm -r --cached .

Dharman
  • 30,962
  • 25
  • 85
  • 135
HamiltonPharmD
  • 582
  • 3
  • 19
  • I run this as the last command again and it did not work, I still have my .pack file there – Michal Aug 28 '20 at 15:00
  • Unfortunately, your suggestion will not remove the file from history, which is what really needs to happen to slim things down. And either way, pack files are not under version control... it's the actual database of the versions. Deleting them is a bad idea. :-) – John Szakmeister Aug 28 '20 at 19:35