How to remove history of deleted git subtree folde

2019-04-09 19:56发布

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.

1条回答
来,给爷笑一个
2楼-- · 2019-04-09 20:19

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

查看更多
登录 后发表回答