2

enter image description here

In my Serenity Java testing project, after the tests have been run, the target and it's sub directory 'site' will be filled with tens of files and directories to display reports and screenshots. Of course, I don't want to commit all those files in to git repository, and even don't want to see them being tracked. I did do this in my .ignore file which is at the top level of the project along with pom.xml as shown.

## Any un needed file any where in the project file structure.

*.class

*.tmp

*.jar

*.html

*.png

*.json

*.csv

*.DS_Store



# any eclipse project file.

.eclipse

.classpath



## All the folders underneath site folder

**/site

site/

site/*



## target folder at the top level of the project structue and paths and contents underneath it

target/

target/*



## target folder at any level of the project structue

**/target

/target 

enter image description here

I am still having the files come up as being tracked...

Community
  • 1
  • 1
PraNuta
  • 629
  • 3
  • 12
  • 33
  • 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) – phd Mar 05 '19 at 06:21
  • https://stackoverflow.com/search?q=%5Bgit%5D+forget+tracked+files – phd Mar 05 '19 at 06:21

3 Answers3

0

Try using the following logic:

!target/
target/site/*

This should spare the target/ folder while including target/site and all its subfolders.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

Those files have accidently tracked before, but .gitignore just works for the files that are not tracked. So adding a .gitignore "too late" results in "not works".

I don't want to commit all those files in to git repository, and even don't want to see them being tracked.

You can use git filter-branch to delete those files from the local history.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
  • I don't need to delete the files from the local history, because, I never committed them at all, not even once. All I want to do is not see them in my git status. I want my 'git status' to be precise and up to the needed point. – PraNuta Mar 06 '19 at 01:18
  • @PraNuta You have accidently committed them before you added .gitignore, otherwise you won't see them "modified" "deleted" (those mean they are tracked). – Geno Chen Mar 06 '19 at 04:04
0

This solved the issue. From the page at How to make Git "forget" about a file that was tracked but is now in .gitignore?

First:

git rm -r --cached . git add . Then:

git commit -am "Remove ignored files"

PraNuta
  • 629
  • 3
  • 12
  • 33