我有一個小的回購有一對夫婦提交的:一個Git復位後,可達承諾不刪除
* 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)做git show a0fc4f8
仍顯示提交
2)做git status
顯示被添加的file.txt
提交a0fc4f8爲未跟蹤和文件你好,是由提交f705657加入也顯示爲未跟蹤。
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的節目a0fc4f8仍顯示提交
更新3:
$ git reflog testbranch
08a2de3 [email protected]{0}: reset: moving to initial
a0fc4f8 [email protected]{1}: commit: added file.txt
e6e6a8b [email protected]{2}: branch: Created from HEAD
'git fcck'在'git gc --prune = all'後面說了什麼? –
@MichałWalenciak:請檢查更新 – Jim
如果您運行'git reset(--mixed)initial',那麼您的工作目錄是未觸及的,這就是爲什麼'a0fc4f8'提交中有所有更改的原因。 – C1sc0