Git - 使用过滤器分支删除带有空变更集的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5324799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git - remove commits with empty changeset using filter-branch
提问by Paul Pladijs
How do I remove commits which have no changeset using git filter-branch?
如何使用 git filter-branch 删除没有变更集的提交?
I rewrote my git history using:
我使用以下方法重写了我的 git 历史记录:
git filter-branch --tree-filter 'rm -r -f my_folder' -f HEAD
this worked out well but now I have lots of commits with empty changesets. I would like to remove those commits. Preferably in msysgit.
这很有效,但现在我有很多提交空变更集。我想删除这些提交。最好在 msysgit 中。
Rebasing is not really an option because I have over 4000 commits and half of them must be removed.
Rebase 并不是一个真正的选择,因为我有超过 4000 次提交,其中一半必须被删除。
采纳答案by Cascabel
Just add on the --prune-empty
option:
只需添加--prune-empty
选项:
git filter-branch --tree-filter 'rm -rf my_folder' --prune-empty -f HEAD
(And of course, if you have other refs, you might want to rewrite everything with -- --all
instead of just HEAD
.)
(当然,如果你有其他引用,你可能想用 重写所有内容,-- --all
而不仅仅是HEAD
。)
Note that this isn't compatible with --commit-filter
; in that case, Charles Bailey has your answer.
请注意,这与--commit-filter
;不兼容。在这种情况下,查尔斯贝利有你的答案。
回答by CB Bailey
Just looking a the documentation for filter-branch
, you should be able to do this:
只需查看 的文档filter-branch
,您就应该能够做到这一点:
git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"' HEAD