git - 使用 git filter-branch 删除除一个子目录之外的所有内容

标签 git subdirectory

我一直在尝试使用 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/

相关文章:

php - 限制 RecursiveIteratorIterator() 递归深度

git - 什么时候(如果有的话)HEAD~ 和 HEAD^ 不是同一个提交?

git - 无效凭据 - git 社区版中的 LDAP 访问错误

git - 当强制推送到远程 git 存储库时,现有标签会发生什么?

date - 清除具有特定参数的目录

windows - 如何使用 CMD 将所有具有特定扩展名的文件从所有子目录移动到它们的父目录?

git - 何时将大型 Git 存储库拆分为较小的存储库?

Git - 处理混合编码文件名

c++ - CMake:防止在子目录库项目中构建测试可执行目标

python - os.walk 对于递归访问文件夹非常慢