Search code examples
gitgit-filter-branch

How can I run git filter-branch on the root commit?


I'm trying to clean up a private project so I can publish it - removing miscellaneous files from the history, etc.

I'm trying to remove a Makefile with git filter-branch. Here's the command line I'm using:

$ git filter-branch -f --index-filter 'git update-index --remove Makefile' 08a7d1..HEAD

However, when I run git log -- Makefile, it shows the Makefile being added in the root commit, then being removed in the commit immediately following the root commit.

How can I get git filter-branch to run on the root commit as well?


Solution

  • The problem is that the starting commit in the commit range you specified (08a7d1..HEAD) isn't inclusive. So basically it's saying "everything that happened after 08a7d1, all the way up to HEAD."

    Passing the commit range to git filter-branch is optional. If you omit it, it will be run on all commits, all the way back to and including the root. So:

    $ git filter-branch -f --index-filter 'git update-index --remove Makefile'
    

    That should do the trick.