[英].gitignore not working for file inside folder
I have the following.gitignore file:我有以下.gitignore 文件:
bin/*
My project has the following structure:我的项目具有以下结构:
myFolder
----bin
-------file
----anotherFolder
----yetAnotherFolder
The.gitignore is located in the folder myFolder
.gitignore 位于文件夹
myFolder
Why is file
still being committed?为什么
file
仍在提交?
There are several ways to use .gitignore
.有几种使用
.gitignore
的方法。
Literal File Names, ex: .myFile
文字文件名,例如:
.myFile
Directories, ex: dir/
目录,例如:
dir/
By adding the
/
in the end, the whole dir is ignored.通过在最后添加
/
,整个目录将被忽略。
Wildcard, ex: *.log
通配符,例如:
*.log
Negation, ex: .example.log
否定,例如:
.example.log
Double Asteriks, ex: **/logs
or logs/**/*.log
双星号,例如:
**/logs
或logs/**/*.log
In your case, you should probably just use bin/
and it will ignore everything from inside that dir.在您的情况下,您可能应该只使用
bin/
它会忽略该目录中的所有内容。
Just put the below in your .gitignore
instead of including the /*
只需将以下内容放在您的
.gitignore
中,而不是包含/*
bin
Will cause all files in that folder to be ignored.将导致该文件夹中的所有文件被忽略。
If you have already committed the file then this won't work.如果您已经提交了文件,那么这将不起作用。
https://git-scm.com/docs/gitignore https://git-scm.com/docs/gitignore
A gitignore file specifies intentionally untracked files that Git should ignore.
gitignore 文件指定 Git 应忽略的故意未跟踪文件。 Files already tracked by Git are not affected;
已被 Git 跟踪的文件不受影响; see the NOTES below for details.
有关详细信息,请参阅下面的注释。
If this is the case for you.如果这是你的情况。 Checkout this answer .gitignore after commit
提交后签出这个答案 .gitignore
If your file is updated during commits, it is because it is tracked.如果您的文件在提交期间被更新,那是因为它被跟踪了。
The.gitignore has no effect on the process of making commits. .gitignore 对提交的过程没有影响。 The.gitignore file has the sole function of not adding files to be tracked.
.gitignore 文件有唯一的 function 不添加要跟踪的文件。 If you issue git add commands with wildcards, or for entire folders recursively, then your.gitignore will kick in and exclude those specified files.
如果您发出 git 添加带有通配符的命令,或者递归地为整个文件夹添加命令,那么 your.gitignore 将启动并排除那些指定的文件。
If you wish to untrack a file, but still have it remain in your repo, then use如果您希望取消跟踪文件,但仍将其保留在您的存储库中,请使用
git rm --cached file
Be careful using git rm
, it deletes files for real!小心使用
git rm
,它会真正删除文件!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.