简体   繁体   English

git log -all显示使用filter-branch删除的提交

[英]git log -all shows commits removed with filter-branch

To remove everything that is not "my_dir/" in my repository history I used: 要删除我使用的存储库历史记录中不是“my_dir /”的所有内容:

git filter-branch --prune-empty --subdirectory-filter my_dir/  --prune-empty --tag-name-filter cat -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d;
git reflog expire --expire=now --all;
git gc --prune=now;

Now, using: 现在,使用:

git log

everything seems fine: the log only shows commits containing files in "my_dir". 一切似乎都很好:日志只显示包含“my_dir”文件的提交。

But: 但:

git log --all

still shows everything. 仍然显示一切。 In fact, doing another filter-branch (to remove some other .pyc files in my_dir) will find (and remove) all the .pyc files in the old dirs. 实际上,执行另一个filter-branch(删除my_dir中的其他.pyc文件)将找到(并删除)旧目录中的所有.pyc文件。

It seems that --subdirectory-filter doesn't really remove the commits... they are still there. 似乎--subdirectory-filter并没有真正删除提交......它们仍然存在。

What am I missing? 我错过了什么?

EDIT: 编辑:

subdirectory-filter "only look at the history which touches the given subdirectory". 子目录过滤器“只查看触及给定子目录的历史记录”。 So maybe it doesn't remove all the other commits, but just rewrites the ones that touch that dir and somehow leaves "orphans" for the others??? 所以也许它不会删除所有其他提交,但只是重写触及该目录的那些并以某种方式为其他人留下“孤儿”???

The filter-branch command creates new refs to the "old" commits in case you need to undo. 如果需要撤消, filter-branch命令会为“旧”提交创建新引用。 git log --all shows the history of all refs, including the special refs that filter-branch created. git log --all显示所有引用的历史记录,包括filter-branch创建的特殊引用。

More generally, the only git command (I can think of) that will actually delete a commit object is gc . 更一般地说,实际上删除提交对象的唯一git命令(我能想到)是gc For gc to remove a commit, it must not be reachable from any ref or from the reflog. 要使gc删除提交,必须无法从任何ref或reflog访问它。 So if you want the commits to be really gone: 所以,如果你想让提交真的消失:

1) Delete the original/* refs 1)删除original/*引用

2) Wipe out the reflog 2)擦除reflog

3) run an aggressive gc with prune=now 3)用prune=now运行一个激进的gc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM