{"thread":{"id":"62532","subject":"git clean --exclude broken?","startedAt":"2024-11-24T11:11:11Z","lastAt":"2024-12-10T02:23:24Z","messageCount":4,"participants":["Homyee King","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"507978","messageId":"1A13EB2A-6075-4CA9-855E-B72ACDA67C0C@gmail.com","threadId":"62532","inReplyTo":null,"subject":"git clean --exclude broken?","fromName":"Homyee King","fromEmail":"homyeeking@gmail.com","sentAt":"2024-11-24T11:10:57Z","receivedAt":"2024-11-24T11:11:11Z","isPatch":false,"sender":{"key":"homyeeking@gmail.com","avatar":null},"body":"13 years ago, Todd Rinaldo found that —exclude option is not works with any options, for example, `git clean -Xd -e=foo` to clean the files/folders respect the .gitignore rule except the foo, but in real world, git only respect the git ignore standard rule and not work with -e option.\n\nToday, 13 years later, the problem still exist, so I wonder is this a bug or should we clarify the “correct” usage of exclude in documentation, because it’s really confusing.\n\nThe discussion can be viewed by this link: https://git.vger.kernel.narkive.com/ulppacPK/clean-exclude-broken\n\nLooking forward to your reaply!"},{"id":"507981","messageId":"Z0Nsq3lQZKJZxd-y@tapette.crustytoothpaste.net","threadId":"62532","inReplyTo":"1A13EB2A-6075-4CA9-855E-B72ACDA67C0C@gmail.com","subject":"Re: git clean --exclude broken?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-11-24T18:12:59Z","receivedAt":"2024-11-24T18:13:07Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-11-24 at 11:10:57, Homyee King wrote:\n> 13 years ago, Todd Rinaldo found that —exclude option is not works\n> with any options, for example, `git clean -Xd -e=foo` to clean the\n> files/folders respect the .gitignore rule except the foo, but in real\n> world, git only respect the git ignore standard rule and not work with\n> -e option.\n> \n> Today, 13 years later, the problem still exist, so I wonder is this a\n> bug or should we clarify the “correct” usage of exclude in\n> documentation, because it’s really confusing.\n\nI don't think this is the right syntax.  For example, I did this in my\ncheckout of the Git project:\n\n----\n$ touch foo\n$ git clean -n\nWould remove foo\n$ git clean -n -e foo\n$ git clean -f -e foo\n$ ls foo\nfoo\n----\n\nWhen you use a short option, you don't specify the equals sign.  So you\ncan write `-e foo`, `-efoo`, `--exclude foo`, or `--exclude=foo`.\nHowever, `-e=foo` is equivalent to `-e =foo`, which ignores `=foo`.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"},{"id":"508308","messageId":"Z0jZfltm0O3y9QoW@tapette.crustytoothpaste.net","threadId":"62532","inReplyTo":"CABAKogYaajvedff2ihsC5g+156L-Oe2N_XR3c+uyyfoovVQ5gg@mail.gmail.com","subject":"Re: git clean --exclude broken?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-11-28T20:58:38Z","receivedAt":"2024-11-28T20:58:42Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-11-26 at 06:13:44, Homyee King wrote:\n> Thanks for replying.\n> It's a typo mistake, the correct command is `git clean -Xdn -e foo` but the\n> problem still exists which is `--exclude` option not work with `-X`, is\n> that design so or a bug? For example:\n> \n> simple-project/ │ ├── foo/ │\n> |---- bar/ ├── .gitignore # contains foo/ bar/ │ └── test.ts # untracked\n> file\n> \n> I only want to clear all gitignored files/folder but *`foo/` *and keep the\n> untrakced files/folders, so here's the command\n> $ git clean -Xdn -e foo\n> $  ls\n> $  Would remove foo/ bar/\n\nI don't think there's a command for what you want to do here.  You\nbasically want to clear only ignored files, but exclude one pattern from\nthe ignore rules.  `-e` doesn't do that: it _adds_ to the ignore rules,\nnot subtracts from them.\n\nSo this is what I'd expect to see here with your file structure:\n\n----\n% git clean -Xdn -e test.ts\nWould remove bar/\nWould remove foo/\nWould remove test.ts\n----\n\nsince by using `-e`, we've added the additional files to be ignored, and\nwith `-X`, we've said to remove the files.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"},{"id":"508901","messageId":"Z1emFS-L-f4caBJ1@tapette.crustytoothpaste.net","threadId":"62532","inReplyTo":"CABAKogZQ4bAh-KPE79q0W7iBBoRmxW26RK_6VSg=6Y-Sg68tig@mail.gmail.com","subject":"Re: git clean --exclude broken?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-12-10T02:23:17Z","receivedAt":"2024-12-10T02:23:24Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-12-09 at 04:53:24, Homyee King wrote:\n> But if you try *git clean -xdn -e foo*, the *foo *will be excluded and not\n> what you said *\"it _adds_ to the ignore rules\".  *It's the confusing part\n> of *`-e` *option, and I think it should always exclude something within the\n> given pattern.\n> If we follow what you said, it should be *--include,* what do you think?\n\nThe `--exclude` option means \"exclude this (mark this as ignored)\nadditionally\".  I agree it could be misinterpreted, but `--include`\ncould as well.  The manual page says this about `-e`:\n\n  Use the given exclude pattern in addition to the standard ignore rules\n  (see gitignore(5)).\n\nAnd the text says this about `-x`:\n\n  Don’t use the standard ignore rules (see gitignore(5)), but still use\n  the ignore rules given with -e options from the command line. This\n  allows removing all untracked files, including build products. This\n  can be used (possibly in conjunction with git restore or git reset) to\n  create a pristine working directory to test a clean build.\n\nThat means that when you say `git clean -xdn -e foo`, Git ignores only\n`foo`, and says it will remove everything else that would normally be\nignored (which is no longer ignored, and thus untracked).  Remember that\n`git clean` only removes untracked files and directories, and `-x` just\nmakes all files normally ignored untracked temporarily for the life of the\ncommand.  Equivalent text exists in the description section of the\nmanual page.\n\nI don't think this is confusing or that the text is inaccurate, but of\ncourse if you want to submit a patch to improve the text, I'm sure we'd\nbe happy to take a look.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"}]}