我无法将目录添加到.gitignore文件中

3
我无法将“taget”目录添加到“.gitignore”文件中。我做了一些不好的事情 :-(
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"已被忽略,但我仍然可以在“git状态”中看到“MyProject/target*”和“MyProject/.settings”。请问我做错了什么?谢谢!

可能是.gitignore文件无法忽略的重复问题。 - poke
2个回答

6

1) 提交所有更改的代码。

2) 修复.gitignore文件。

3) 运行git rm -r --cached .

这将删除索引中的所有内容。

4) 运行git add .

5) 运行git commit -m “.gitignore现在可用”

现在它可以工作了 :-)


4

您需要使用git rm --cached从索引中删除文件。 gitignore文件仅适用于尚未提交的文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接