Reputation: 2103
Is there a way to pass git filter-branch
a regular expression to remove files/directories permanently from the history?
Upvotes: 2
Views: 1847
Reputation: 129564
Assuming you want to do an index filter (which won't need to change your work tree), you can script on all commits and only change the files you need by sed, egrep or grep on the output of git ls-files
.
git ls-files --cached | \
sed 's/weirdprefix\(pattern\)/git reset HEAD weirdprefix\1/g' | \
xargs -i{} sh -c '{}'
(this is the script you would provide in the filter-branch command)
Here is an example from the documentation ( http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html ):
git filter-branch --index-filter \
'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
Upvotes: 3