Gitignore不会忽略指定的文件夹/文件 [英] Git ignore doesn't ignore the specified folders/files
问题描述
我希望我的.gitignore忽略某些文件夹和文件,所以我提出了以下建议:
I want my .gitignore to ignore certain folders and files so I came up with the following:
*.class
# usual java ignores
bin/
.metadata
# Maven
*/target/*
target/*
/target/
*/deploy/*
deploy/*
# src-gen folder is populated by the command of protobuf, these files should not be pushed
src-gen/*
# eclipse generated stuff
dependency-reduced-pom.xml
# we shouldn't have .jar files in our repository,
# apart from these 5 jars which are vital for our build process
*.jar
!/projectName/bundle/**/*.jar
# For Unix editors
# sometimes make file copies ending
# with ~
# To ignore them use:
*~
# For Mac
.DS_Store
._*
# For markdown read me files
.README.md.html
但是,在git status
之后,我看不到任何要删除的内容作为输出.请注意,如果这很重要,则这是一个子模块.而且我希望此.gitignore
忽略所有内容而不指定任何文件夹名称,因为我不需要任何硬编码.
However, after a git status
I cannot see anything to be deleted as output. Note that this is a submodule, if that matters at all. And I want this .gitignore
to ignore everything without specifying any folder name, since I don't want any hardcoding.
这是我的文件夹结构:
+ parentRepo
+ thisRepo
+ .gitignore
+ projectName
+ src-gen
+ target
+ deploy
+ dependency-reduced-pom.xml
+ bundle
+ system
+ 1.jar
+ 2.jar
+ 3.jar
+ 4.jar
+ 5.jar
推荐答案
我看不到任何要删除的内容" –您只是告诉git
忽略了一些文件;现在您希望它删除它们?
"I cannot see anything to be deleted" -- you just told git
to ignore some files; now you expect it to delete them?
.gitignore
仅用于尚未跟踪的文件(即,将新文件添加到存储库时).如果文件已经在存储库中,并且您希望git
忽略它,则必须将其从存储库(git rm --cached file
)中删除并提交更改.
.gitignore
is used only for files that are not already tracked (i.e when new files are added to the repository). If the file is already in the repository and you want git
to ignore it then you have to remove it from the repository (git rm --cached file
) and commit the change.
这篇关于Gitignore不会忽略指定的文件夹/文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!