如何从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-rf<目录名>

删除目录后,通过以下方式提交更改:gitcommit-m“您的提交消息”

然后只需在远程GIT目录上推送更改:git推送原点<分支名称>

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

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 rm -r folder_name
git commit -m "your commit"
git push origin master

在删除任何内容之前,第一个git命令需要知道您是谁

初始化git-config user.name“某人”git-config user.email“someone@someplace.com"git rm-rgitcommit-m“删除目录”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