我无法将“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 status”MyProject / target *和MyProject / .settings中看到。 你能帮我解决一下我的坏事吗? 谢谢!
答案 0 :(得分:4)
1)提交所有更改的代码。
2)修复.gitignore
3)git rm -r --cached。
这将删除索引中的所有内容。
4)git add。
5)git commit -m“.gitignore正在工作”
现在可行: - )
答案 1 :(得分:2)
您需要使用git rm --cached
从索引中删除文件。 gitignore文件仅适用于尚未提交的文件。