3

Git correctly ignores everything in my target folder (maven) except folder "surefire-reports".

My .gitignore:

# Java
*.class
.idea/

# Package Files
*.jar
*.war
*.iml
*.ucls
target/

But files in target\surefire-reports\ still tracked by git. See git status output:

# On branch connectionPane
# 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:   target/surefire-reports/TEST-navalwar.ConsolePlayerTest.xml
#   modified:   target/surefire-reports/navalwar.ConsolePlayerTest.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   gitstatus.txt
no changes added to commit (use "git add" and/or "git commit -a")

There are other folders and file in target\ but git don't track them!

pattivacek
  • 5,617
  • 5
  • 48
  • 62
AlexeyGorovoy
  • 760
  • 5
  • 23

1 Answers1

3

If those files have previously been checked in to git, git will still pay attention to them even though they otherwise meet the criteria for ignoring. Since they have been modified, we know that they have been previously checked in.

See here: How to make Git "forget" about a file that was tracked but is now in .gitignore? and Ignoring an already checked-in directory's contents?

Short answer: this will do the job and not delete the file locally:

git rm -r --cached <your directory>
Community
  • 1
  • 1
pattivacek
  • 5,617
  • 5
  • 48
  • 62
  • I working on this project for a two weeks, and today I wrote first unit-test. And I sure these files are results of maven test phase. – AlexeyGorovoy Jul 23 '13 at 13:46
  • I don't think I understand your comment. Do you mean that you don't think those files were supposed to be checked in? They are listed as `modified`, meaning someone checked them in and they have since changed in your working copy. – pattivacek Jul 23 '13 at 13:48
  • 1
    Thank you for explanation (I still don't have an idea how those files were checked in if target\ was always in gitignore), but for now problem solved by the way you suggested. – AlexeyGorovoy Jul 23 '13 at 14:05
  • Could someone else have checked them in? Otherwise, you can check something ignored in if you force it. Admittedly, it's probably hard to do that by accident. – pattivacek Jul 23 '13 at 14:08
  • It's my local repo and accessed only by me, so it's surely happend for my fault :) – AlexeyGorovoy Jul 23 '13 at 14:12