问题
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
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.
Here is the folder structure I have:
+ parentRepo
+ thisRepo
+ .gitignore
+ projectName
+ src-gen
+ target
+ deploy
+ dependency-reduced-pom.xml
+ bundle
+ system
+ 1.jar
+ 2.jar
+ 3.jar
+ 4.jar
+ 5.jar
回答1:
"I cannot see anything to be deleted" -- you just told git
to ignore some files; now you expect it to delete them?
.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.
回答2:
Make sure that your .gitignore
is in the root directory. In that directory run git status
and copy the path to the file from the status output and paste it into the .gitignore
.
.gitignore
will only ignore files that you haven't already added to your repository.
来源:https://stackoverflow.com/questions/38658458/git-ignore-doesnt-ignore-the-specified-folders-files