没有应用对gitignore的更改

时间:2014-03-01 07:43:11

标签: git gitignore

我在git跟踪的文件夹中有多个项目。我的原始.gitignore除了* *.java之外,在某些项目中除了*之外什么都没有。现在我正在启动另一个项目,我已经添加或者更确切地将其包含在.gitignore文件中以跟踪它们,但是在进行提交git时告诉我The following paths are ignored by one of your .gitignore files:。我可以使用-f来强制跟踪项目文件,但我想知道为什么git没有应用我对.gitignore所做的更改。

我原来的.gitignore。

.gitignore
# Ignore everything
*

# Except for these files
!Assignment1/
!Assignment1/*.java
!Assignment2/
!Assignment2/*.java
!Assignment3/
!Assignment3/*.java
!Assignment4/
!Assignment4/*.java
!Assignment5/
!Assignment5/*.java
!Assignment6/                                                                                                                                                          
!Assignment6/*.java
!README.md

我现在的.gitignore。您现在可以看到我想跟踪Assignment7中的所有.java文件。

.gitignore
# Ignore everything
*

# Except for these files
!Assignment1/
!Assignment1/*.java
!Assignment2/
!Assignment2/*.java
!Assignment3/
!Assignment3/*.java
!Assignment4/
!Assignment4/*.java
!Assignment5/
!Assignment5/*.java
!Assignment6/                                                                                                                                                          
!Assignment6/*.java
!Assignment7/                                                                                                                                                          
!Assignment7/*.java
!README.md

添加!Assignment7/!Assignment7/*.java后,当我运行git add .git add -A时,命令运行没有任何问题,但不会跟踪Assignment7文件。

[donnie@fedora workspace]$ git add .
[donnie@fedora workspace]$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

[donnie@fedora workspace]$ git add -A
[donnie@fedora workspace]$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

尝试通过添加位置添加文件告诉以下

[donnie@fedora workspace]$ git add Assignment7
The following paths are ignored by one of your .gitignore files:
Assignment7
Use -f if you really want to add them.
fatal: no files added
[donnie@fedora workspace]$ git add Assignment7/*.java
The following paths are ignored by one of your .gitignore files:
Assignment7/FacePamphlet.java
Assignment7/FacePamphletCanvas.java
Assignment7/FacePamphletConstants.java
Assignment7/FacePamphletDatabase.java
Assignment7/FacePamphletProfile.java
Use -f if you really want to add them.
fatal: no files added

我可以通过添加-f来解决这个问题,但我想知道我错过了什么。为什么我无法跟踪添加到.gitignore文件中的文件。

感谢。

编辑: - 类似问题12没有那么有用,因为.git位于顶级目录中,而要跟踪的文件位于子目录中。

1 个答案:

答案 0 :(得分:0)

  

您的.gitignore文件之一将忽略以下路径:

要了解更多信息并了解导致该消息的原因是哪个gitignore文件的哪个规则,请使用git check-ignore

git check-ignore -v -- Assignment7/FacePamphlet.java

通常,您可以使用:

*
!/**/
!*.java