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


当前回答

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

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

其他回答

您可以使用Attlasian源树(Windows)(https://www.atlassian.com/software/sourcetree/overview). 只需从树中选择文件并按下顶部的“删除”按钮。文件将从本地存储库和本地git数据库中删除。然后提交,然后推送。

如果由于某种原因,karmakaze所说的不起作用,您可以尝试使用或使用文件系统浏览器(例如,在Windows文件资源管理器中)删除您想要的目录。删除目录后,发出命令:git add-A然后gitcommit-m'删除目录'然后git推送原始主机。

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

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

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

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

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

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

我执行了以下操作:

将文件夹添加到.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中删除,但没有从本地磁盘中删除。