devoid
devoid

Reputation: 1039

git filter-branch only change affected commits

A large binary file was added to my git repository 20 commits ago. Removing this with:

git filter-branch --index-filter "git rm --cached --ignore-unmatch FILE" \
    --prune-empty HEAD

changes the SHA1 for every commit (~1100) in my projects history. It does remove the file, but I was hoping to only have git push -f a small number of modified commits. Is there a way to tell filter-branch to only modify commits with FILE and descendant comments, in my case around 20 commits?

Upvotes: 3

Views: 1180

Answers (1)

Lily Ballard
Lily Ballard

Reputation: 185841

If you know what commit introduced the file, the simplest way is to specify $SHA^..HEAD (where $SHA is the commit that introduced it). This will prevent it from even looking at older commits.

If the commit that introduced this file only introduced it, and nothing more, and no other commits since then touched it, then you can get rid of it even simpler without a filter-branch, by using git rebase --onto $SHA^ $SHA (where $SHA is the commit that introduced this file). That will simply drop the commit $SHA from history.

Upvotes: 6

Related Questions