2

I have a clone of the project from another team then I run it a few times. I checked, the size of this project increased significantly. From 2MB as when the new clone until now is 190MB.

I checked and found that this increase was caused by the .git/objects folder.

I tried something like git gc --prune=now --aggressive but nothing changed.

I can delete the project and clone again but I think there is a way for the project to keep the same size as when I first cloned. So is there a way to refresh my project to the way it was when I cloned?

project

===================================================================

EDIT 2: I follow the steps in Remove large .pack file created by git but the pack file (.git/objects/xxxxxxxxx.pack) keeps 200 MB. It's ridiculous but what I want is just to make my project as small as when I first cloned. But it seems that git is not capable of providing this.

My workaround was to delete all files and try to clone the project again.

Huy Nguyen
  • 21
  • 2
  • 2
    Provide an argument of -- depth 1 to the git clone command to copy only the latest revision of a repo: `git clone -–depth [depth] [remote-url]` You can also use git shallow clone to access a single branch: `git clone [remote-url] --branch [name] --single-branch [folder]` – Eyal Gerber Dec 27 '22 at 11:53
  • `git rev-list --objects --all` should give you an idea what is it that takes up all that space in your `.git/objects` directory. Just cloning a single commit should be much safer than forcibly removing commit history and branches. It is also unclear from your question, what happened during when you ran the project. Sometimes there are submodules in a project which need to be populated for a build, but those will increase the size of `.git/modules` subdirectory. – jpe Dec 27 '22 at 13:01
  • 2
    Did somebody commit large binary files? Even deleting them from a subsequent commit will still keep the old commit around. [How to find/identify large commits in git history?](https://stackoverflow.com/q/10622179/112968) – knittl Dec 27 '22 at 13:40
  • I just cloned from another team and I don't even know to commit anything. What I want is for it to be the same size as the first clone. Expected size is `2MB`, not `200MB` like this. – Huy Nguyen Dec 27 '22 at 13:44
  • Maybe the other team committed a large file. When work is being done in a repository, it will grow in size, that's to be expected. If a fresh clone still ends up with 200M, then that's the size of the repo. If you need the history, there's no way around. If you don't need the history, consider shallow clones. – knittl Dec 27 '22 at 13:45
  • @knittl No, if I clone a new source code, it only takes up 2 MB. – Huy Nguyen Dec 27 '22 at 13:57
  • But I just want to clean up my local repo, make it fetched as clone. As @jpe mentions, I run `git rev-list --objects --all` and see many lines... How to free up it. I don't want to keep anything except the source code like the remote repository. – Huy Nguyen Dec 27 '22 at 14:02
  • What do you mean by "I run it a few times"? Running a code in a project shouldn't affect the repo state, unless you project code intentionally does that for some reason. So what you need to do is to make a new clone, and reproduce the problem, this time identifying the exact thing you did that changed its size. Come back and give us all the details here. – Inigo Dec 28 '22 at 09:31

0 Answers0