简体   繁体   English

Git从推送到存储库中排除文件夹

[英]Git exclude folder from pushing to repository

My repository consists of two folders client and server . 我的存储库由两个文件夹clientserver In server I have few folders which were automatically generated by Codeblocks IDE like bin and obj . server我有几个文件夹是由Codeblocks IDE自动生成的,例如binobj I dont want to store them in my repository, so I decided to add .gitignore . 我不想将它们存储在我的存储库中,所以我决定添加.gitignore I tried everything: 我尝试了一切:

# folders
**/bin/
**bin/
**/bin
**bin
bin
/bin
bin/
/bin/
server/bin
/server/bin
server/bin/
server/bin

And still after pull and making git status I can see that bin folder will be pushed. 仍然在pull并设置git status我可以看到bin文件夹将被推送。 What am I doing wrong? 我究竟做错了什么?

In comments, you show that each file is listed as a "new file". 在注释中,您显示每个文件都被列为“新文件”。 You don't specify whether these show as "changes to be committed" or "untracked files"; 您无需指定它们是显示为“要提交的更改”还是“未跟踪的文件”; but in the case of untracked files, if no files in a directory are tracked then only the directory (not the individual files) would be listed by default. 但是对于未跟踪的文件,如果目录中没有文件被跟踪,则默认情况下仅列出目录(而不是单个文件)。

So it seems the problem is that files in these directories are in the index, which means git can't ignore them. 看来问题在于这些目录中的文件都在索引中,这意味着git无法忽略它们。 You could remove them from the index 您可以将它们从索引中删除

git rm -r --cached server/bin
git rm -r --cached server/obj

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM