Re: git clean deletes negated pathspec if directory causing data loss
- From
- Devste Devste <devstemail@gmail.com>
- Date
- Oct 5, 2025, 11:33 UTC
- Message-ID
- <CANM0SV3iRF=jVAFj=+rrgOC_nXEJ=_v1bUG88n3T9+PQD=a2-A@mail.gmail.com>
- In-Reply-To
- <CANM0SV0R7OYJKeBAs5-WY2Wqp7VxhKv5=LQ4cuDd6MaQwNqGNw@mail.gmail.com>
Just to clarify: it's not about the negation not working, but clean ignores the pathspec for ignored directories completely. I only want to delete .rej and .log files, but it will also delete gitignored directories (that may or may not contain any .rej or .log files)
On Sun, 5 Oct 2025 at 13:27, Devste Devste <devstemail@gmail.com> wrote:
Show 16 quoted lines
>
> I am using:
> git version 2.51.0.windows.1
>
> Run:
> echo .idea/dictionaries >> .gitignore
> mkdir -p .idea/dictionaries
> touch .idea/dictionaries/foo.xml
> git clean -f -f -d -X --dry-run -- ':!/.idea/dictionaries' ':*.rej' ':/*/*.log'
>
> Outputs:
> Would remove .idea/dictionaries/
>
> No matter how you specify the pathspec (':!.idea',...) it always wants
> to delete the .idea/dictionaries directory, even though it does not
> contain any .rej or .log files and is explicitly set to excluded