0

Super simple question I am sure I am missing but just can't find what:

Here is how my repository looks like:

enter image description here

In this .gitignore file there is the following content:

*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.settings
target
.project
.classpath
.springBeans
.metadata
Servers
.recommenders
.classpath
/Spring4SoapProducer/target/

Where most important is the last line. I want the target folder of this not to be under source control.

But as you can already guess it is. I am getting this when I go for git status in folder directory localy.

enter image description here

I tried like all variations like /Spring4SoapProducer/target/, Spring4SoapProducer/target/, ./Spring4SoapProducer/target/, */target

Well none of it helped also I am commiting the .gitignore file before trying get status again .

Someone please I'm sure it is something stupid that I am missing!

Lazar Lazarov
  • 2,412
  • 4
  • 26
  • 35

2 Answers2

2

If a file is already under version control, then Git will not ignore the file even if it's in the .gitignore file. The answer is that you need to remove the files in that directory from version control. Then, with your ignore in place, Git will ignore all files under that directory.

My answer in another question might help you with doing this: Removing .xcuserstate and DS_Store files from git

Community
  • 1
  • 1
John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
2

Try this:

git rm --cached <file>

it should would remove <file> from version control, while keeping it in the working repository.