如何从Git存储库中删除包含文件的单个目录?


当前回答

从Git和本地删除目录

使用两个目录签出“master”:

git rm -r one-of-the-directories // This deletes from filesystem
git commit . -m "Remove duplicated directory"
git push origin <your-git-branch> (typically 'master', but not always)

从Git中删除目录,但不是本地目录

要从Git中删除此目录,但不将其从文件系统(本地)中完全删除,请执行以下操作:

git rm -r --cached myFolder

其他回答

这两个答案的组合对我有用

git rm -r one-of-the-directories
git commit . -m "Remove duplicated directory"
git push

如果仍然显示一些警告,请手动删除文件

git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
git push

从Git和本地删除目录

使用两个目录签出“master”:

git rm -r one-of-the-directories // This deletes from filesystem
git commit . -m "Remove duplicated directory"
git push origin <your-git-branch> (typically 'master', but not always)

从Git中删除目录,但不是本地目录

要从Git中删除此目录,但不将其从文件系统(本地)中完全删除,请执行以下操作:

git rm -r --cached myFolder

我通常使用gitadd-all从远程存储库中删除文件/文件夹

rm -r folder_name
git add --all
git commit -m "some comment"
git push origin master

master可以被存储库的任何其他分支替换。

你可以试试这个:git rm-rf<目录名>

它将强制删除目录。

我的一位同事建议BFG Repo Cleaner,我认为它很强大。它不仅可以删除不需要的数据,还可以清除存储库中的任何相关提交信息。