2012-10-14 187 views
1

我做了一些測試提交(測試提交掛鉤),並始終將索引重置爲最後一次正常提交。現在這些陳舊的提交仍然存在:從Git中刪除陳舊的提交

> git reflog 
fcdabf7 [email protected]{0}: reset: moving to fcdabf7e01845d6f000fc3cef2edc999c57a7e29 
5c97564 [email protected]{1}: commit: t 
fcdabf7 [email protected]{2}: reset: moving to fcdabf7e01845d6f000fc3cef2edc999c57a7e29 
ae52246 [email protected]{3}: commit: t 
fcdabf7 [email protected]{4}: reset: moving to fcdabf7e01845d6f000fc3cef2edc999c57a7e29 
c58aeef [email protected]{5}: commit: t 
fcdabf7 [email protected]{6}: reset: moving to fcdabf7e01845d6f000fc3cef2edc999c57a7e29 
3a2cc3b [email protected]{7}: commit: test 

我該如何刪除它們?爲了技術上的理解:如果我讓他們獨自一人,如果我推一推,他們會被推到上游回購區嗎?

+2

Afaik您將只推送可通過您推送的分支到達的提交。如果它不在'git log'中,則不會被推送。也可以嘗試用'git gc'來清除無法訪問的提交。 – ZeissS

+0

我嘗試過'git gc --aggressive --prune = 2015-01-01',但是這並沒有將它們從reflog中移除。 – AndiDog

+0

請參閱http://stackoverflow.com/q/1904860/11343 – CharlesB

回答

0

承諾通過引用日誌條目引用不晃來晃去本身。要清除引用日誌,

git reflog expire --expire=0 --all 

事後這git prune可以用來刪除 - 現在,晃來晃去 - 承諾。

+0

這有效,'git gc --aggressive --prune = now'刪除了提交。當然,這意味着我每次執行此操作時都會丟失reflog。 – AndiDog

0

首先,您不必擔心懸掛提交到遠程存儲庫的方式。他們不會被推,並且通常會在適當的時候清理。

但是,如果你想清除掉這樣晃來晃去的對象,嘗試運行:

git gc --prune=now