The Problem
If i understand you correctly, you have 3 folders in your total git history: src, AAA and BBB.
for basically the hole history, you had only src, and in the end you made one commit where you separated files from src into AAA and BBB, thus removing src, and creating the two others.
in schematic history view (each line is a commit, latest/newest commit is on top, like in gitk):
AAA, BBB
src
src
src
src
.
.
.
If you now use git filter-branch --prune-empty -subdirectory-filter AAA
,
it will remove everything, from every commit in history that is not inside folder AAA (and then make AAA the new root dir). As folder AAA exists only in a single commit in your history, you will be left only with this single commit.
Solution
There are multiple ways to solve this, but i will explain only what i think is most general and probably most compatible with more complex situations.
How to create the AAA sub-repo by rewriting the whole history
- locally clone your repo, and work only with the clone
- Remove the last commit where you manually separated the files into AAA and BBB.
Write a (shell-)script, that removes all files that are should not be part of AAA, for example using:
git rm --cached --ignore-unmatch "${fileName}"
Use this script to rewrite every command in your history, with something like:
git filter-branch --prune-empty --index-filter "myCleanupScript.sh" HEAD
(NOTE This last step will likely take a long time!)