如何正确忽略GitHub中的文件夹?

时间:2016-10-08 14:32:26

标签: git gitignore

在我的.gitignore文件中,我添加了一条文件夹路径,我想在GitHub网站上看到:

Results/.ipynb_checkpoints/

然后我推动这个改变:

git commit -a -m "add ignore"
git push origin master

但是当我去网站时,我仍然看到这个文件夹。如何正确地做到这一点?

2 个答案:

答案 0 :(得分:3)

您现在需要删除.gitignore中的文件夹。您可以通过在本地删除文件夹,添加更改,提交然后再推送它来完成此操作。如果您需要本地存储库中的文件夹,则可以在删除之前通过备份来恢复它。

如果您不想在本地删除该文件夹,只需从远程删除,则可以执行以下操作:

git rm -r --cached Results/.ipynb_checkpoints/
git commit -m "Removed folder from repository"
git push origin master

有关从远程存储库中删除文件/文件夹的更多信息,但在this question and answers中可以读取

答案 1 :(得分:1)

删除本地存储库中的目录use myuser; insert into customers values (3, "Julie Smith", "25 Oak Street", "Airport West"), (4, "Alan Wong", "1/47 Haines Avenue", "Box Hill"), (5, "Michelle Arthur", "357 North Road", "Yarraville"); insert into orders values (NULL, 3, 69.98, "2007-04-02"), (NULL, 1, 49.99, "2007-04-15"), (NULL, 2, 74.98, "2007-04-19"), (NULL, 3, 24.99, "2007-05-01"); insert into books values ("0-672-31697-8", "Michael Morgan", "Java 2 for Professional Developers", 34.99), ("0-672-31745-1", "Thomas Down", "Installing Debian GNU/Linux", 24.99), ("0-672-31509-2", "Pruitt, et al.", "Teach Yourself GIMP in 24 Hours", 24.99), ("0-672-31769-9", "Thomas Schenk", "Caldera OpenLinux System Administration Unleashed", 49.99); insert into order_items values (1, "0-672-31697-8", 2), (2, "0-672-31769-9", 1), (3, "0-672-31769-9", 1), (3, "0-672-31509-2", 1), (4, "0-672-31745-1", 3); insert into book_reviews values ("0-672-31697-8", "Morgan's book is clearly written and goes well beyond most of the basic Java books out there.");

.ipynb_checkpoints

然后做

git rm -rf '.ipynb_checkpoints'

添加更改(包括删除事件),

git rm --cached '.ipynb_checkpoints'

提交

git add -A .

将更改推送到服务器(远程存储库)

git commit -m "Clean working directory"