1

I have this directory structure:

.gitignore
text1.txt
public
--static
----uploaded-files
------picture1.jpg

this is the content of .gitignore

.idea
public/static/

UPDATE: using git version 2.11.0.windows.1 when i run git clean -nd to list what untracked files and directories would be removed it says:

Would remove .gitignore
Would remove public/
Would remove text1.txt

even though git status doesnt show public/ but shows .gitignore

So when i run git clean -fd its removes public that i want to keep instead

Can somebody please explain why git removes this ignored directory and files in it? Is it because .gitignore gets cleaned first in process and then public is not being ignored while executing this command? or my .gitignore is wrong?

How can i achieve not losing ignored directories but ofc getting rid of untracked files?

UPDATE: with git version 2.17.1.windows.2 public/ directory is no longer part of would remove

patrikw
  • 15
  • 1
  • 5
  • Can't replicate the issue with Git 2.18.0.windows.1. What if adding `.gitignore` to ignore .gitignore itself? – ElpieKay Jul 21 '18 at 12:12
  • @ElpieKay while posting this issue i was using git version git version 2.11.0.windows.1 (forgot to mention it - UPDATED NOW) after that, i installated git version git version 2.17.1.windows.2 and suprisingly when i run git clean -nd public/ directory is no longed part of "Would remove".. maybe it is connected somehow to https://stackoverflow.com/questions/23148736/git-clean-removes-ignored-files-by-default#_=_ – patrikw Jul 21 '18 at 12:42
  • It is indeed connected to the question you linked-to. Note that Git in general is largely unconcerned with *directories* as it really only stores *files*. Directories just get added as needed to *hold* files. The `git clean` command has to have an exception to this general rule because of its ability to *remove* directories, and they just got it wrong until Git 2.14. – torek Jul 21 '18 at 14:55
  • (BTW this is an example of a very useful duplicate, since people concerned about directory removal would find this question, rather than the one I've marked as the duplicate.) – torek Jul 21 '18 at 14:56

0 Answers0