Title basically.
I just mixed some things up with my .gitignore
and bloated my .git
dir to > 100mb (it's a repo with like 100commits total..).
So I'm a lazy guy and was wondering if it would be possible to delete my history. I don't want to rebase something or stuff, I just want to shrink my .git
dir size.
When there is no way to do this I just would git clone --depth 1
my repo to get the same effect.
Those are two conflicting goals:
delete the history implies a brand new repo (rm -Rf .git
, git init .
): that means you have to force push your new local repo with a git push --force
, destroying the history on the remote repo as well,
keeping the remote repo intact means locally working with git clone --depth 1
, which is safe to do since Git 2.0, as I have documented here (ie. you can push back to a remote repo from a local shallow repo)
The second approach seems the safest for:
Note: for a local repo with its full history, git gc
and git repack
alone are not enough to really shrink the size of a .git
folder.
See "git gc --aggressive
vs git repack
".
git gc
git repack -Ad # kills in-pack garbage
git prune # kills loose garbage
(That would not do much on a freshly cloned repo, that would only be effective on a local repo you have been working for some time)
Plus, if you did in the past operations like git filter-branch
, your .git
folder would still keep a folder like .git/refs/original/
that you need to delete if you want to reduce the size of .git/
.
AFAIU the original question and how I want to do it is precisely without removing
.git
folder, just removing local copy of git log data to make its' state identical to the state aftergit clone --depth 1
See "Converting git repository to shallow?"
You can try:
cd /my/repo
git show-ref -s HEAD > .git/shallow
git reflog expire --expire=0
git prune
git prune-packed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With