2012-10-14 73 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