views:

70

answers:

1

I have a git tree like

                 A---B---C topic
                /
           D---E---F---G master     <--

I would like to remove topic and all objects on it.

I note the SHA ID of topic, then type:

git branch -D topic
git gc                                   #  <-- I also tried prune here...
git checkout -b temp <SHA1 ID of topic>

After the last command I expect to get an error (something like "Non-existent object ID..." or somth. like that). However there is no error and gitk shows the same tree structure as above??

What am I missing - I thought gc/prune are supposed to delete all unreachable objects?

+3  A: 

Note: As mentioned by Jakub, if your branch was merged, topic would still be reachable.

Here, let's suppose there was no merge.
Then, as mentioned in the ProGit book and detailed in this SO question:

git gc --prune=now

should be enough (you should call directly git prune). You can control that with a git count-objects -v.

VonC
"Unreachable" is actually even stronger than you imply here. As far as `git-gc` is concerned, an object is reachable if it's reachable from a reflog - and reflogs take a long time to expire. For example, you could've merged the branch to master, realized it was bad and reset master back to the previous position, and the commit would be considered reachable until the reflog entry expired (default 90 days).
Jefromi
Also, it probably goes without saying, but be super-extra-careful using `--prune=now`. It'd be awful to realize just after hitting enter that some other important commit got wiped away.
Jefromi
thanks guys, you rock! :)
Alan