{"thread":{"id":"63854","subject":"[feature] git clean ignored files in nested repositories support","startedAt":"2025-07-26T12:01:01Z","lastAt":"2025-08-01T19:00:22Z","messageCount":2,"participants":["Alon Bar-Lev"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"522786","messageId":"CAOazyz08vf65ezNMuUyOCYYHBGmDSeCtzXn=WdZAWGO9ZjCkAQ@mail.gmail.com","threadId":"63854","inReplyTo":null,"subject":"[feature] git clean ignored files in nested repositories support","fromName":"Alon Bar-Lev","fromEmail":"alon.barlev@gmail.com","sentAt":"2025-07-26T12:00:42Z","receivedAt":"2025-07-26T12:01:01Z","isPatch":false,"sender":{"key":"alon.barlev@gmail.com","avatar":"https://gravatar.com/avatar/622377544f34b20b5709c97512490a702224fa29bd4f8f3de1fcb1c7932dc73a?d=mp&s=160"},"body":"Hi,\n\nI am sure this was discussed in the past, I could not find any\nexplicit discussion.\n\nThe `git clean` is a handy command, it can clean directories,\nincluding ignore files and also handle nested git repositories if a\nsecond -f is given.\n\n    git clean -dxff\n\nHowever, as far as I understand, it is not possible to clean ignored\nfiles in nested repositories, the `x` is applied only to the local\nrepository.\n\nAs workaround following command may be used:\n\n    git clean -dxff && git submodule foreach git clean -dxff\n\nHowever, I expect the double `f` to take into account the `x` and also\nclean ignored files from the nested repository.\n\nI am unsure if this is a bug or intentional.\n\nIf this is intentional, maybe a patch to have a second -x would be\nacceptable? so that we could have something like:\n\n   git clean -dxxff\n\nAny other suggestions? It would be nice to be able to clean the entire\ntree with a simple git clean command consistently in all scenarios.\n\nRegards,\nAlon\n"},{"id":"523233","messageId":"CAOazyz32EAhqXmSTG7BVW2gLkgJort5ghR4+e2PjSn_b5pcBYg@mail.gmail.com","threadId":"63854","inReplyTo":"CAOazyz08vf65ezNMuUyOCYYHBGmDSeCtzXn=WdZAWGO9ZjCkAQ@mail.gmail.com","subject":"Re: [feature] git clean ignored files in nested repositories support","fromName":"Alon Bar-Lev","fromEmail":"alon.barlev@gmail.com","sentAt":"2025-08-01T19:00:02Z","receivedAt":"2025-08-01T19:00:22Z","isPatch":false,"sender":{"key":"alon.barlev@gmail.com","avatar":"https://gravatar.com/avatar/622377544f34b20b5709c97512490a702224fa29bd4f8f3de1fcb1c7932dc73a?d=mp&s=160"},"body":"Hello,\n\nI tried to trace the code and it seems like there is a bug or\ndifferent behavior than the documented behavior, the recursive\nimplementation in `dir.h` is quite complex, this is not a trivial fix.\n\n\"\"\"\nman git-clean\n       -f, --force\n           If the Git configuration variable clean.requireForce is not\nset to false, git clean will refuse to delete files or directories\nunless given -f or -i. Git will refuse to\n           modify untracked nested git repositories (directories with\na .git subdirectory) unless a second -f is given.\n\"\"\"\n\nI expect untracked files to be removed from the nested git directory\nwhen `git clean -dxff` is executed, previously I thought that the\nignored files were the issue.\n\nReproduction:\n\n```\nmkdir test\ncd test\ngit init .\ngit commit -a -m \"root\" --allow-empty\ngit submodule add https://github.com/git/htmldocs module1\ngit commit -a -m \"init\"\ntouch module1/junk.txt\ngit status\nOn branch master\nChanges not staged for commit:\n  (use \"git add <file>...\" to update what will be committed)\n  (use \"git restore <file>...\" to discard changes in working directory)\n  (commit or discard the untracked or modified content in submodules)\nmodified:   module1 (untracked content)\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\n```\n\nNow, clean recursive and allow nested (double `-f`):\n\n```\ngit clean -dxff\ngit status\nOn branch master\nChanges not staged for commit:\n  (use \"git add <file>...\" to update what will be committed)\n  (use \"git restore <file>...\" to discard changes in working directory)\n  (commit or discard the untracked or modified content in submodules)\nmodified:   module1 (untracked content)\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\n```\n\nExpected behavior: the `module1/junk.txt` removed.\nActual behavior: the `module1/junk.txt` remains.\n\nFor some reason I remember that a few years ago this worked as\nexpected, at least in removing untracked files recursively and in\nnested repositories.\n\nThanks,\nAlon\n\n\nOn Sat, 26 Jul 2025 at 15:00, Alon Bar-Lev <alon.barlev@gmail.com> wrote:\n>\n> Hi,\n>\n> I am sure this was discussed in the past, I could not find any\n> explicit discussion.\n>\n> The `git clean` is a handy command, it can clean directories,\n> including ignore files and also handle nested git repositories if a\n> second -f is given.\n>\n>     git clean -dxff\n>\n> However, as far as I understand, it is not possible to clean ignored\n> files in nested repositories, the `x` is applied only to the local\n> repository.\n>\n> As workaround following command may be used:\n>\n>     git clean -dxff && git submodule foreach git clean -dxff\n>\n> However, I expect the double `f` to take into account the `x` and also\n> clean ignored files from the nested repository.\n>\n> I am unsure if this is a bug or intentional.\n>\n> If this is intentional, maybe a patch to have a second -x would be\n> acceptable? so that we could have something like:\n>\n>    git clean -dxxff\n>\n> Any other suggestions? It would be nice to be able to clean the entire\n> tree with a simple git clean command consistently in all scenarios.\n>\n> Regards,\n> Alon\n"}]}