I have been trying to use git to remove everything except the source code in a particular branch. The
git filter-branch -f \
--subdirectory-filter source_code \
--prune-empty \
--tag-name-filter cat -- --all
command gets me basically what I want, except it places the files in source_code/
at the root, whereas I want them all to remain in the directory. I.e.
- source_code
- file1.py
- file2.py
not just
- file1.py
- file2.py
How can I do this?
You need --tree-filter:
git filter-branch \
--tree-filter "find . -type f -not -wholename './source_code/*' -delete" HEAD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With