Git如何从git删除文件夹和文件?

问题描述

我过去有一些文件夹包含在git commit中,现在我想从git中删除它。所以我在.gitignore中添加了该文件夹。但是,如果我尝试从服务器提取更改,则会抛出错误拉出失败。一些未跟踪的工作树文件将被Pull覆盖。请先移动或卸下它们,然后才能拉动。 在.gitignore中是行

/storage 

应该忽略存储目录中的所有内容。那么,为什么pull在storage / logs / 20201455.log文件中的文件有问题?我不明白。谢谢您的帮助。

解决方法

除了提及生物技术专家,您还可以执行以下操作:

git rm -r --cached storage

这只会将其从存储库中删除并保留文件,请记住,您必须在.gitignore文件中添加./storage,以确保不会再次将其添加到存储库中。

,

如果存储目录已经签到您的存储库,则需要将其删除:

git rm -r storage
git commit -m "Removed storage"

但是这也会删除存储目录的内容,因此请先将其移动到安全的地方。

mv storage storage_orig
git rm -r storage
git commit -m "Removed storage"
mv storage_orig storage