我如何/可以在git存储库中完全核对变更集?

时间:2011-07-25 16:39:47

标签: git

我正在尝试真正删除git存储库中的更改集。我正在使用git reset --hard,但似乎我仍然可以恢复旧的变更集:

% 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

为什么我在执行bye命令后仍然可以使用标记mytag签出git reset --hard ...提交?我认为git reset --hard应该完全破坏那些编辑?有没有办法真正真正地改变变革集?

1 个答案:

答案 0 :(得分:2)

简短回答:“不”。 git reset只会移动您的分支点。孤立提交(未包含在任何分支或标签中)将在符合条件后进行垃圾收集 - 默认情况下为两周后。 Git在管理存储方面做得很好,所以就让它做它的事情。

相关问题