0

I'm trying filter a directory in my repo while reserving only the commit history regarding the filtered directory.

I've managed to do most of the work following these steps:

  1. filter the directory using git filter-branch -f --subdirectory-filter MY_DIR --tag-name-filter cat --prune-empty -- --all
  2. remove empty commits using git filter-branch -f --tag-name-filter cat --commit-filter 'git_commit_non_empty_tree "$@"' -- --all

These two steps pruned most of the unwanted commits but I am still left with empty merge commits (which had to do with files outside of my filtered directory). I've read that --prune-empty only removes commits that have exactly one parent so I'm not surprised that I'm left with these merge commits. But how do I remove them?

P.S. I've tried both parent-filters suggested here: Prune empty merge commits from history in Git repository

But as someone wrote in the comments, these parent-filters don't remove merge commits done by two empty commits (which are literally all the merge commits I want to remove).

Alon Levy
  • 78
  • 1
  • 5

0 Answers0