Reputation: 24228
I'm trying to really delete changesets in a git repository. I'm using git reset --hard
, but it still seems that I can recover the old changesets:
% git init
Initialized empty Git repository in /tmp/ross/test/.git/
% echo hi > hi; git add hi; git commit -m hi hi
[master (root-commit) 3ef4ac5] hi
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 hi
% echo bye > bye; git add bye; git commit -m bye bye
[master 966b136] bye
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 bye
% git tag mytag
% git log # grab the 'hi' sha number
% git reset --hard 3ef4ac559079c3b463374a51fb460d46ade396dc
HEAD is now at 3ef4ac5 hi
% git checkout mytag
Note: checking out 'mytag'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 966b136... bye
Why can I still checkout the bye
commit with tag mytag
after I did the git reset --hard ...
command? I thought git reset --hard
was supposed to completely nuke those edits? Is there a way to really really nuke the changesets?
Upvotes: 0
Views: 786
Reputation: 128849
Short answer: "no". git reset
only moves around what your branch points at. Orphaned commits (those not contained in any branches or tags) will be garbage collected after they become eligible--after they're two weeks old by default. Git does a good job of managing its storage, so just let it do its thing.
Upvotes: 2