Example
So let's say I have a local git repo with 10 commits, having SHA digests 0-9 so my git log looks like this
9 (HEAD -> master)
8
7
6
5
4
3
2
1
0 <- initial commit
and I decide that commits 5-9 are garbage and I would like to permanently delete all record of them from the repositoy and the disk space they introduced. Baiscally, I want the state of my repo to be the same as it was when commit 4 was made, and have it be like 5-9 never even happened.
I know that git reset --hard 4
will make my repo appear to have been rewinded to commit 4, but from what I understand, that merely changes the commit master
points to from 9 to 4 but does not actually delete anything. All the data is still there, and is recoverable if you know the SHA of commit 9.
I am also aware of git filter-branch
but that only removes files from the history, not commits.
Ive tried doing:
git reset --hard 4
git gc --prune=now
but after doing this, the disk space usage of my .git
directory is the same or bigger, and I can still recover the history with git checkout 9
. Why does git gc --prune=now
not prune commits 5-9? Do I need to expire my reflog
?
More Generally:
If I have a complex repo with many branches, tags, commits, merges and divergant history, How can I permanently and automatically remove all commits, along with the changes they introduce, and the disk space they consume, that occured after a certain time. Effectively rewinding the entire repo to that time and permanently destroying all activity that occurred after that date.