问题描述
我使用git-subtree添加了一个git仓库。问题是我在硬件重新加入git-subtree之前做了一次硬重置。现在提交历史记录仍在存储库中,但与主服务器断开连接。
任何想法如何删除它?我试过git rm - 没有运气的缓存。
要立即删除已经无法访问的提交,这可能是您的子树提交的情况,可以使用以下命令:
git reflog expire --all --expire -reachable = 0
git repack -A -d
git prune
git gc
will不会立即收集无法访问的提交,因为这些(在默认配置中)需要首先过期,然后不能与其他可到达的提交打包在一起。这可能会在一段时间后自行发生,或者您可以使用上面的命令强制执行它。
还要考虑到任何对您的子树提交的引用都会阻止它们存在收集,这包括braches,标记和reflog引用。确保你确实没有悬挂对这些提交的引用。
这里还有一个关于如何处理不可达提交的更详细的问题:
I added a git repository using git-subtree. The problem is that I did a hard reset back to before the repository was added with git-subtree. Now the commit history is still in the repository but it's disconnected from master.
Any idea how to remove it? I tried git rm --cached with no luck.
To remove right away commits that are already unreachable, which would be the case of your subtree commits, you can use the following commands:
git reflog expire --all --expire-unreachable=0
git repack -A -d
git prune
git gc
will not immediately collect unreachable commits, since these (in the default configuration) need first to expire and then to not be packed with other reachable commits. This happens on its own after a while, or you can force it with the commands above.
Also take into consideration that any reference to your subtree commits will prevent them from being collected, this includes braches, tags, and reflog references. Make sure you really have not dangling references to these commits.
Here is also a more detailed question on how to dispose unreachable commits:
Garbage collect commits in git
这篇关于如何删除删除的git子树文件夹的历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!