2

I have a two .gitignore files because one didn't work in the past and I had to create the second one; they which looks:

/target/
.idea/

and .gitignore.gitignore which looks:

*/target/**
/target/**
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
target/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
.idea/

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/

and still it includes those files which are in .gitignore - why?enter image description here

bielas
  • 672
  • 2
  • 12
  • 29
  • Did you try removing on of the .gitignore files ? – xsami May 23 '17 at 20:51
  • Should I remove .gitignore file? I haven't done it.. – bielas May 23 '17 at 20:52
  • Just keep the one that has the configuration that u require. because it may be causing any kind of conflict when git tries commit – xsami May 23 '17 at 20:53
  • Have you committed those files before? The workspace.xml and application.properties – Alan Perez May 23 '17 at 20:55
  • You should try to also add: `.idea/*.*` – xsami May 23 '17 at 20:55
  • I deleted .gitignore.gitignore and still has those errors. Yes I used to commit them.. – bielas May 23 '17 at 20:57
  • Look at this https://stackoverflow.com/a/936290/5295199 – Alan Perez May 23 '17 at 20:58
  • @AlanPerez doesn't work for me – bielas May 23 '17 at 20:59
  • git rm --cached ../../../../.idea/workspace.xml git rm --cached ../../../../target/classes/application.properties This should remove the files from the repository – Alan Perez May 23 '17 at 21:01
  • I did it and still can't change the branch because: On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) deleted: ../../../../.idea/workspace.xml deleted: ../../../../target/classes/application.properties – bielas May 23 '17 at 21:04
  • I commited it and still has the same file `modified`: Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: ../../../../.idea/workspace.xml – bielas May 23 '17 at 21:10
  • This means the gitignore is not properly setup. Delete the custom one you wrote and use the .gitignore.gitignore by renaming it to .gitignore – Alan Perez May 23 '17 at 21:49
  • Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – 1615903 May 24 '17 at 05:16

1 Answers1

6

.gitignore only works for untracked files. If files are already part of HEAD revision, then .gitignore won't be considered for it. If you want to remove the file from previous revisions, you should consider rewriting history to get rid of them from the history of your branch.

eftshift0
  • 26,375
  • 3
  • 36
  • 60