Re: git clean --exclude broken?
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Dec 10, 2024, 02:23 UTC
- Message-ID
- <Z1emFS-L-f4caBJ1@tapette.crustytoothpaste.net>
- In-Reply-To
- <CABAKogZQ4bAh-KPE79q0W7iBBoRmxW26RK_6VSg=6Y-Sg68tig@mail.gmail.com>
On 2024-12-09 at 04:53:24, Homyee King wrote:
Show 5 quoted lines
> But if you try *git clean -xdn -e foo*, the *foo *will be excluded and not > what you said *"it _adds_ to the ignore rules". *It's the confusing part > of *`-e` *option, and I think it should always exclude something within the > given pattern. > If we follow what you said, it should be *--include,* what do you think?
The `--exclude` option means "exclude this (mark this as ignored) additionally". I agree it could be misinterpreted, but `--include` could as well. The manual page says this about `-e`:
Use the given exclude pattern in addition to the standard ignore rules (see gitignore(5)).
And the text says this about `-x`:
Don’t use the standard ignore rules (see gitignore(5)), but still use the ignore rules given with -e options from the command line. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git restore or git reset) to create a pristine working directory to test a clean build.
That means that when you say `git clean -xdn -e foo`, Git ignores only `foo`, and says it will remove everything else that would normally be ignored (which is no longer ignored, and thus untracked). Remember that `git clean` only removes untracked files and directories, and `-x` just makes all files normally ignored untracked temporarily for the life of the command. Equivalent text exists in the description section of the manual page.
I don't think this is confusing or that the text is inaccurate, but of course if you want to submit a patch to improve the text, I'm sure we'd be happy to take a look.
-- brian m. carlson (they/them or he/him) Toronto, Ontario, CA