2

git clean -d -f removes directories containing files which are ignored. Can I keep the ignored files and still run git clean -d?

Example:

dir\dir2\file1

.gitignore:

dir\dir2

git clean -d -f removes dir and all it's contents. I would expect it to realize that i'm ignoring dir\dir2\file1 and not delete file1.

Arne Claassen
  • 14,088
  • 5
  • 67
  • 106
Coder
  • 1,375
  • 2
  • 20
  • 45
  • You will, soon, with git 1.8.4 and its ***interactive*** `git clean` mode: http://stackoverflow.com/a/17802455/6309 – VonC Jul 23 '13 at 18:08
  • That is very useful but it's not exactly what i'm looking for. I would think given that git clean has a -x and -X parameters it can read the .gitignore file, If i don't specify -x or -X i would expect it to leave my ignored files where they are, but it doesn't – Coder Jul 23 '13 at 18:30

1 Answers1

0

I've observed the same behavior and cannot find it listed in a bug. It's certainly still the behavior in git 2.0.4.

The work-around i've found it to add a dummy file in the empty directory that is contains the ignored file, so that it is no longer considered by -d, e.g.

/dir
  /dir2
    /file1
    /.marker

Being a .dotfile it's ignored from directory listing, so it's fairly unobtrusive and it does keep the directory put.

Arne Claassen
  • 14,088
  • 5
  • 67
  • 106