git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git clean --exclude broken?

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Nov 28, 2024, 20:58 UTC
Message-ID
<Z0jZfltm0O3y9QoW@tapette.crustytoothpaste.net>
In-Reply-To
<CABAKogYaajvedff2ihsC5g+156L-Oe2N_XR3c+uyyfoovVQ5gg@mail.gmail.com>
On 2024-11-26 at 06:13:44, Homyee King wrote:
Show 14 quoted lines
> Thanks for replying.
> It's a typo mistake, the correct command is `git clean -Xdn -e foo` but the
> problem still exists which is `--exclude` option not work with `-X`, is
> that design so or a bug? For example:
> 
> simple-project/ │ ├── foo/ │
> |---- bar/ ├── .gitignore # contains foo/ bar/ │ └── test.ts # untracked
> file
> 
> I only want to clear all gitignored files/folder but *`foo/` *and keep the
> untrakced files/folders, so here's the command
> $ git clean -Xdn -e foo
> $  ls
> $  Would remove foo/ bar/

I don't think there's a command for what you want to do here. You basically want to clear only ignored files, but exclude one pattern from the ignore rules. `-e` doesn't do that: it _adds_ to the ignore rules, not subtracts from them.

So this is what I'd expect to see here with your file structure:

---- % git clean -Xdn -e test.ts Would remove bar/ Would remove foo/ Would remove test.ts ----

since by using `-e`, we've added the additional files to be ignored, and with `-X`, we've said to remove the files.

-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
Previous: brian m. carlsonNext: brian m. carlson
Message 3 of 4 in “git clean --exclude broken?”
  1. Homyee KingNov 24, 2024
  2. brian m. carlsonNov 24, 2024
  3. brian m. carlsonNov 28, 2024
  4. brian m. carlsonDec 10, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.