I want a way to remove (really remove) a commit or a branch from a git repository, for nothing but to save space, i tried to use 'git branch -d branch-name' to remove a branch or 'git reset Head~ --hard' but both just remove or move the branch head, and still the commit exists, and i can reassign a branch head to any commit.
isn't there a way to do this without removing the entire repository folder and reinitialize?
Git builds a nice safety net around your actions, which once in a whille really saves your foot from beeing obliterated. It is strongly not advised to do what you want to do in a regular daily workflow.
That being said : the commands you are looking for are git gc
and git prune
.
See for example this SO question :
git gc --aggressive vs git repack
You may also need to clear your reflog :
git gc --aggressive --prune=all does not remove big file from repository
Again : the reflog is like a massive undo stack ; if you throw its content away, no more undos.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.