Git - remove commits with empty changeset using filter-branch

GitGit Filter-Branch

Git Problem Overview


How do I remove commits which have no changeset using git filter-branch?

I rewrote my git history using:

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.

Rebasing is not really an option because I have over 4000 commits and half of them must be removed.

Git Solutions


Solution 1 - Git

Just add on the --prune-empty option:

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.)

Note that this isn't compatible with --commit-filter; in that case, Charles Bailey has your answer.

Solution 2 - Git

Just looking a the documentation for filter-branch, you should be able to do this:

git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"' HEAD

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPaul PladijsView Question on Stackoverflow
Solution 1 - GitCascabelView Answer on Stackoverflow
Solution 2 - GitCB BaileyView Answer on Stackoverflow