I want to delete all files that are neither "foo" nor "bar" in git repository history. Given that rm -rf !(foo|bar) works for deleting files in the current directory that are neither "foo" nor "bar". I came up with the following idea:
$ git filter-branch --tree-filter 'rm -rf !(foo|bar)' --prune-empty HEAD
However, this produced the following error which I really don't understand why it doesn't work.
Rewrite 75c1ec1ef083338ca2e88db9cc6107c1630d91e9 (1/871)~/libexec/git-core/git-filter-branch: 1: eval: Syntax error: "(" unexpected
rmin this context.