我一直在尝试使用 git 删除特定分支中除源代码之外的所有内容。
git filter-branch -f \
--subdirectory-filter source_code \
--prune-empty \
--tag-name-filter cat -- --all
命令基本上得到了我想要的,除了它将文件放在 source_code/
的根目录中,而我希望它们全部保留在目录中。即
- source_code
- file1.py
- file2.py
不仅仅是
- file1.py
- file2.py
我该怎么做?
最佳答案
你需要--tree-filter :
git filter-branch \
--tree-filter "find . -type f -not -wholename './source_code/*' -delete" HEAD
关于git - 使用 git filter-branch 删除除一个子目录之外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38847555/