Search code examples
gitgit-rewrite-historybfg-repo-cleaner

Git: Remove everything except for a certain directory (BFG Repo Cleaner)


I am trying to permanently remove all traces of all directories in a Git repository except for one directory, say named keep-me.

For such tasks, the BFG repo cleaner is my usual go-to tool. However, it does not seem to support this operation (in fact, I believe it does not support extended globs). I am really trying to accomplish the following, which does not get rid of the other directories:

java -jar ~/bfg-1.12.12.jar --delete-folders {!(keep-me)} my-repo.git

Thanks!


Solution

  • You can do it the other way round:

    git subtree split --prefix keep-me --branch cleaned-branch
    

    This will create a new project history in the branch cleaned-branch which only contains keep-me.