我有一个小仓库,有几个提交:
* a0fc4f8 (HEAD -> testbranch) added file.txt
* e6e6a8b (master) hello world now
* f308f53 Made it echo
* f705657 Added hello
* 08a2de3 (tag: initial) initial
还:
$ git status
On branch testbranch
nothing to commit, working directory clean
我无法理解以下行为。在这种状态下我运行:
$ git reset initial
我现在看到:
* e6e6a8b (master) hello world now
* f308f53 Made it echo
* f705657 Added hello
* 08a2de3 (HEAD -> testbranch, tag: initial) initial
我所期待的:提交 a0fc4f8 将被删除,因为它无法访问。
发生了什么:
1) Doinggit show a0fc4f8
仍然显示提交
2) Doing将提交 a0fc4f8 添加的git status
显示file.txt
为未跟踪,提交 f705657 添加的文件 hello 也显示为未跟踪。
3) 运行git gc
或git gc --prune=all
不删除 a0fc4f8,尽管它不再可访问并且没有与之关联的名称/标签。
为什么会发生这些?
更新:
$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (15/15), done.
更新 2:
$ git log --all --decorate --graph --oneline
* e6e6a8b (master) hello world now
* f308f53 Made it echo
* f705657 Added hello
* 08a2de3 (HEAD -> testbranch, tag: initial) initial
$ git gc --force
Counting objects: 15, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (15/15), done.
Total 15 (delta 1), reused 15 (delta 1)
$ git log --all --decorate --graph --oneline
* e6e6a8b (master) hello world now
* f308f53 Made it echo
* f705657 Added hello
* 08a2de3 (HEAD -> testbranch, tag: initial) initial
$ git show a0fc4f8 仍然显示提交
更新 3:
$ git reflog testbranch
08a2de3 testbranch@{0}: reset: moving to initial
a0fc4f8 testbranch@{1}: commit: added file.txt
e6e6a8b testbranch@{2}: branch: Created from HEAD