1

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?

Mohamed Ali
  • 3,717
  • 1
  • 33
  • 39

1 Answers1

3

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.

LeGEC
  • 46,477
  • 5
  • 57
  • 104