12

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
Schütze
  • 1,044
  • 5
  • 28
  • 48

3 Answers3

44

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

axiac
  • 68,258
  • 9
  • 99
  • 134
5

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.

Aakash
  • 1,455
  • 13
  • 16
  • So, I will have only 1 .gitignore (in the parent directory) and it will do everything for the submodules as well? – Schütze Jul 29 '16 at 12:14
  • Yes, but make sure that the files you want to ignore, you did not add the files already to the git repo. – Aakash Jul 29 '16 at 12:15
  • [Some](http://stackoverflow.com/a/5127213/6533075) say differently about 1 `.gitignore` for all. – Schütze Jul 29 '16 at 12:26
  • There can be multiple `.gitignore` files in any sub directories but the Best Practice is to have one `.gitignore` in a given projects root. Otherwise it is tricky to know "which" `.gitignore` file to look at to find something that's being ignored. Given that you can use patterns as file names that could be pretty tricky! – Aakash Jul 29 '16 at 12:28
0

so late but helpful!

i had the same problem with bin and obj folders!

i found i uploaded them before in my repository!

so i deleted them from repository and stashed all files, then synced with repo , the problem solved