从Git删除过时的提交 [英] Remove stale commits from Git

查看:83
本文介绍了从Git删除过时的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了一些测试提交(以测试提交钩),并且始终将索引重置为我的上次正常提交。现在,这些陈旧的提交仍然存在:

 > git reflog 
fcdabf7 HEAD @ {0}:重置:移至fcdabf7e01845d6f000fc3cef2edc999c57a7e29
5c97564 HEAD @ {1}:提交:t
fcdabf7 HEAD @ {c}:重置:移动至fcdabfa7e7845 $ b ae52246 HEAD @ {3}:提交:t
fcdabf7 HEAD @ {4}:重置:移至fcdabf7e01845d6f000fc3cef2edc999c57a7e29
c58aeef HEAD @ {5}:提交:t
fcdabf7 HEAD @ { 6}:重置:移至fcdabf7e01845d6f000fc3cef2edc999c57a7e29
3a2cc3b HEAD @ {7}:提交:测试

如何删除它们?并且出于技术上的理解:如果我不理会它们,如果我进行推送,是否会将它们推送到上游回购协议?

解决方案

reflog条目引用的提交本身并不悬挂。要清除reflog,

  git reflog expire --expire = 0 --all 

之后,可以使用 git修剪删除-现在悬而未决的提交。 / p>

I have made some test commits (to test a commit hook) and always reset the index to my last normal commit. Now these stale commits still exist:

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

How can I remove them? And for technical understanding: If I leave them alone, will they be pushed to the upstream repo if I do a push?

解决方案

Commits referenced by the reflog entries are not dangling per se. To clear the reflog,

git reflog expire --expire=0 --all

afterwards which git prune can be used to remove the - now-dangling - commits.

这篇关于从Git删除过时的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆