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


当前回答

如果您正在从GitHub web应用程序中删除目录,您将找到一个删除选项。然而,在这之后,它会给你一个被删除的文件列表,底部有提交选项。请记住提交它。否则,目录将不会被删除。

参考-https://docs.github.com/en/repositories/working-with-files/managing-files/deleting-files-in-a-repository

其他回答

如果您正在从GitHub web应用程序中删除目录,您将找到一个删除选项。然而,在这之后,它会给你一个被删除的文件列表,底部有提交选项。请记住提交它。否则,目录将不会被删除。

参考-https://docs.github.com/en/repositories/working-with-files/managing-files/deleting-files-in-a-repository

我之前已经提交了该文件夹,并希望删除历史记录中的目录。

我执行了以下操作:

将文件夹添加到.gitignore:

echo Folder_Name/ >> .gitignore

从所有提交中删除:

git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch Folder_Name/' --prune-empty --tag-name-filter cat -- --all

从旧提交中删除refs:

git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d

确保完全删除所有旧引用

rm -Rf .git/logs .git/refs/original

执行垃圾收集

git gc --prune=all --aggressive

将更改推送到在线存储库:

git push

你到此为止。

但您可以通过以下操作将所有更改推送到所有分支:但是要小心这个命令!

git push origin --all --force
git push origin --tags --force

之后,该文件夹从git中删除,但没有从本地磁盘中删除。

转到git目录,然后键入以下命令:rm-rf<目录名>

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

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

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

初始化git-config user.name“某人”git-config user.email“someone@someplace.com"git rm-rgitcommit-m“删除目录”git推送原始主机

您可以在本地删除文件夹,然后按如下方式推送:

git rm -r folder_name
git commit -m "your commit"
git push origin master