Domanda

I can't add "taget" directory to ".gitignore" file. I do something bad :-(

martin@martin:~/git/gitRepo$ tree -L 3 -a
.
├── .git
  ...
├── .gitignore
└── MyProject
    ├── .classpath
    ├── pom.xml
    ├── .project
    ├── .settings
  ...
    ├── .springBeans
    ├── src
    │   ├── main
    │   └── test
    └── target
        ├── classes
        ├── m2e-wtp
        └── test-classes

269 directories, 32 files
martin@martin:~/git/gitRepo$ 
martin@martin:~/git/gitRepo$ cat .gitignore 
*.*~
*.class
*.jar
*.war
*.ear
MyProject/.classpath
MyProject/.project
MyProject/.settings/
MyProject/target/
/MyProject/target/
target
martin@martin:~/git/gitRepo$ 
martin@martin:~/git/gitRepo$ git status 
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .gitignore
#   modified:   MyProject/.settings/org.eclipse.wst.validation.prefs
#   modified:   MyProject/target/classes/log4j.xml
#   modified:   MyProject/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF
#   modified:   MyProject/target/m2e-wtp/web-resources/META-INF/maven/example.net/gitRepo/pom.properties
#   modified:   MyProject/target/m2e-wtp/web-resources/META-INF/maven/example.net/gitRepo/pom.xml
#
no changes added to commit (use "git add" and/or "git commit -a")
martin@martin:~/git/gitRepo$ 

"MyProject/.classpath" is in ignore list, but I still see in "git status" MyProject/target* and MyProject/.settings. Can you please help me what I do bad? Thank you!

È stato utile?

Soluzione

1) Commit all changed code.

2) Fix .gitignore

3) git rm -r --cached .

This removes everything from the index.

4) git add .

5) git commit -m ".gitignore is now working"

Now it works :-)

Altri suggerimenti

You need to remove the files from the index using git rm --cached. The gitignore file only applies to files that haven't already been committed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top