How to preserve all ignored files in git clean -fd?

When I have .gitignore data/* and run git clean -fd, the data folder and all its content files are deleted.

What I want is to delete all unrevisioned files in a git repo while excluding all ignored files (i.e. DON’T delete gitignored files). What could I do?

  • Installing modules with Julia
  • Fetch specific commit from remote git repo
  • What user will Ansible run my commands as?
  • Why would git log/status return no output?
  • Jenkins remote build issue - email related
  • what happened to a commit that doesn't show up in any branches but available in “git show”
  • gitignore without binary files
  • Forgot to create new branch. How to transfer changes to new branch
  • Making a git project read only
  • Timed out compiling Play 2.x - Java app (15 minutes) | Heroku and Play Framework
  • How to make bash suppose all commands to be git commands?
  • Remove files from the staging area
  • One Solution collect form web for “How to preserve all ignored files in git clean -fd?”

    Git normally don’t clean ignored files unless you specify the -x flag, but strangely it cleans out when configured as you did (folder/*).

    As @VonC commented it out, you should change your .gitignore to ignore the directory (data/) rather than what’s in it (data/*).

    It’s a subtle difference, but it matters to git.

    Git Baby is a git and github fan, let's start git clone.