Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignore doesn't ignore the specified folders/files

Tags:

git

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

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
like image 225
Schütze Avatar asked Jul 29 '16 12:07

Schütze


1 Answers

"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.

like image 75
axiac Avatar answered Oct 25 '22 14:10

axiac