Reputation: 534
I have added a folder containing millions of files with git add
and deleted them using git rm -r FolderPath
. Then I commited git commit
and the object folder size in .git reaches to more than 250mb. So when I try to push the repository, it literally doesn't do the job duo to large number of files.
I tried many ways like git add -u
, git gc
, git gc --prune=now --aggressive
, etc. but non of them solved the problem.
Finally I deleted the object folder and everything messed up. So I can neither push or pull.
Anyone know a simple way to avoid these scenarios?
Upvotes: 0
Views: 44
Reputation: 489748
The best way is: Don't put in commits you don't want to put in.
Every commit adds to the repository. A repository is nothing more than a large collection of commits.
All commits are completely, totally read-only. No part of any commit can ever be changed.
Every commit has a full snapshot of all of its files. If the file in the snapshot is the same as some previous file in some previous snapshot, Git can and does re-use the previous file. If the snapshot doesn't have some previous file, it just doesn't have the file. That doesn't change the previous snapshot. You're still just adding a snapshot: it's just one that does not have the file.
It is possible to remove a commit, sort of. To do this, though, you must remove every subsequent (descendant) commit as well, because part of each commit is the commit-hash-ID of its previous commit, which must exist. So if you put in a big commit by mistake, it's easy to remove it when it's still the last commit. But if you add more commits on top of it, you now have to remove every commit from the bad one on.
I'll leave the rest to How do I undo the most recent local commits in Git?
Upvotes: 2