简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM