{"thread":{"id":"53559","subject":"[Feature request] Add -u option to git rm to delete untracked files","startedAt":"2020-05-26T21:21:27Z","lastAt":"2020-05-27T19:31:58Z","messageCount":5,"participants":["Erik Janssen","Jeff King","Đoàn Trần Công Danh","Randall S. Becker"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"398603","messageId":"1098602171.79502.1590528083387@mail.ziggo.nl","threadId":"53559","inReplyTo":null,"subject":"[Feature request] Add -u option to git rm to delete untracked files","fromName":"Erik Janssen","fromEmail":"eaw.janssen@chello.nl","sentAt":"2020-05-26T21:21:23Z","receivedAt":"2020-05-26T21:21:27Z","isPatch":false,"sender":{"key":"eaw.janssen@chello.nl","avatar":null},"body":"Hello All,\n\n\nWould it be feasible to add a -u option to git rm to specify that I also want a file deleted if it is not tracked by git?\nCurrently, git rm -f can remove files in whatever state it seems, except when it is untracked. \nBy allowing a -u option (-u: also delete untracked files) I would be sure that the file is gone while it would also make sure that it doesn't break past behaviour where people perhaps rely on git rm to leave untracked files alone.\n\n\nKind regards,\n\n\nErik Janssen.\n"},{"id":"398617","messageId":"20200527073432.GD4006199@coredump.intra.peff.net","threadId":"53559","inReplyTo":"1098602171.79502.1590528083387@mail.ziggo.nl","subject":"Re: [Feature request] Add -u option to git rm to delete untracked files","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-05-27T07:34:32Z","receivedAt":"2020-05-27T07:34:34Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 26, 2020 at 11:21:23PM +0200, Erik Janssen wrote:\n\n> Would it be feasible to add a -u option to git rm to specify that I\n> also want a file deleted if it is not tracked by git?\n\nIt might be a little tricky, as I suspect the code is starting from the\nset of tracked files, and then applying the arguments of pathspecs (but\nI didn't look too carefully, so I might be wrong).\n\nThe \"git clean\" command is made for this (and starts by iterating over\nthe filesystem), and does exactly what you want. But I guess you are\nhoping for a state where you can just run \"git rm\" without having to\nthink about whether the file is tracked or not.\n\n-Peff\n"},{"id":"398635","messageId":"20200527124445.GB2013@danh.dev","threadId":"53559","inReplyTo":"1098602171.79502.1590528083387@mail.ziggo.nl","subject":"Re: [Feature request] Add -u option to git rm to delete untracked files","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-05-27T12:44:45Z","receivedAt":"2020-05-27T12:44:50Z","isPatch":false,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2020-05-26 23:21:23+0200, Erik Janssen <eaw.janssen@chello.nl> wrote:\n> Would it be feasible to add a -u option to git rm to specify that\n> I also want a file deleted if it is not tracked by git?\n> Currently, git rm -f can remove files in whatever state it seems,\n> except when it is untracked. \n> By allowing a -u option (-u: also delete untracked files) I would be\n> sure that the file is gone while it would also make sure that it\n> doesn't break past behaviour where people perhaps rely on git rm to\n> leave untracked files alone.\n\nI _think_ remove untracked file is pretty much risky operation,\nand it should be done separately/independently (via git-clean(1)).\n\nLet's assume we have -u|--untracked,\nnothing (probably) can stop our users from:\n\n\tgit rm -u src\n\tgit rm -u .\n\nEven git-clean(1) requires either --force or --interactive\nbecause it's too much risky to begin with.\n\nIf we think Git as a FileSystem, its rm should only care about its\ntracked file. I prefer to just rm(1) instead of \"git-rm -u\".\n\n-- \nDanh\n"},{"id":"398636","messageId":"021801d63433$3f0c5e80$bd251b80$@nexbridge.com","threadId":"53559","inReplyTo":"20200527124445.GB2013@danh.dev","subject":"RE: [Feature request] Add -u option to git rm to delete untracked files","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2020-05-27T14:29:29Z","receivedAt":"2020-05-27T14:29:53Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On May 27, 2020 8:45 AM, Ðoàn Tr?n Công Danh wrote:\n> To: Erik Janssen <eaw.janssen@chello.nl>\n> Cc: git@vger.kernel.org\n> Subject: Re: [Feature request] Add -u option to git rm to delete untracked\n> files\n> \n> On 2020-05-26 23:21:23+0200, Erik Janssen <eaw.janssen@chello.nl> wrote:\n> > Would it be feasible to add a -u option to git rm to specify that I\n> > also want a file deleted if it is not tracked by git?\n> > Currently, git rm -f can remove files in whatever state it seems,\n> > except when it is untracked.\n> > By allowing a -u option (-u: also delete untracked files) I would be\n> > sure that the file is gone while it would also make sure that it\n> > doesn't break past behaviour where people perhaps rely on git rm to\n> > leave untracked files alone.\n> \n> I _think_ remove untracked file is pretty much risky operation, and it should\n> be done separately/independently (via git-clean(1)).\n\nA git alias could easily be set up to do this, of course dangerous because of what git-clean does without any arguments:\n\n    git config --global alias.rmu 'clean -f --'\n\n> Let's assume we have -u|--untracked,\n> nothing (probably) can stop our users from:\n> \n> \tgit rm -u src\n> \tgit rm -u .\n> \n> Even git-clean(1) requires either --force or --interactive because it's too\n> much risky to begin with.\n> \n> If we think Git as a FileSystem, its rm should only care about its tracked file. I\n> prefer to just rm(1) instead of \"git-rm -u\".\n\n"},{"id":"398688","messageId":"1983783029.127560.1590607913242@mail.ziggo.nl","threadId":"53559","inReplyTo":"021801d63433$3f0c5e80$bd251b80$@nexbridge.com","subject":"RE: [Feature request] Add -u option to git rm to delete untracked files","fromName":"Erik Janssen","fromEmail":"eaw.janssen@chello.nl","sentAt":"2020-05-27T19:31:53Z","receivedAt":"2020-05-27T19:31:58Z","isPatch":false,"sender":{"key":"eaw.janssen@chello.nl","avatar":null},"body":"Hello All,\n\nThanks for the responses!\nI was not aware of the alias option, but it gave me the following idea that seems to work:\ngit config --global alias.rmclean '!git rm -r -f $1; git clean -f $1'\n\nA dir with a untracked file 'file1' will give:\ngit rmclean file1\nfatal: pathspec 'file1' did not match any files\nRemoving file1\nbut effectively the file is gone.\n\nA dir with a tracked file 'file2' will give:\ngit rmclean file2\nrm 'file2'\n\nalternatively, ignore the errors:\ngit config --global alias.rmclean '!git rm -r -f $1 2>/dev/null; git clean -f $1 2>/dev/null'\n\nsome setup as above, untracked file1, tracked file2 in one go:\ngit rmclean .\n\ngives:\nrm 'file2'\nRemoving file1\n\nSo I think I solved my own question :-)\n\nKind regards,\nErik.\n\n\n> Op 27 mei 2020 om 16:29 schreef \"Randall S. Becker\" <rsbecker@nexbridge.com>:\n> \n> \n> On May 27, 2020 8:45 AM, Ðoàn Tr?n Công Danh wrote:\n> > To: Erik Janssen <eaw.janssen@chello.nl>\n> > Cc: git@vger.kernel.org\n> > Subject: Re: [Feature request] Add -u option to git rm to delete untracked\n> > files\n> > \n> > On 2020-05-26 23:21:23+0200, Erik Janssen <eaw.janssen@chello.nl> wrote:\n> > > Would it be feasible to add a -u option to git rm to specify that I\n> > > also want a file deleted if it is not tracked by git?\n> > > Currently, git rm -f can remove files in whatever state it seems,\n> > > except when it is untracked.\n> > > By allowing a -u option (-u: also delete untracked files) I would be\n> > > sure that the file is gone while it would also make sure that it\n> > > doesn't break past behaviour where people perhaps rely on git rm to\n> > > leave untracked files alone.\n> > \n> > I _think_ remove untracked file is pretty much risky operation, and it should\n> > be done separately/independently (via git-clean(1)).\n> \n> A git alias could easily be set up to do this, of course dangerous because of what git-clean does without any arguments:\n> \n>     git config --global alias.rmu 'clean -f --'\n> \n> > Let's assume we have -u|--untracked,\n> > nothing (probably) can stop our users from:\n> > \n> > \tgit rm -u src\n> > \tgit rm -u .\n> > \n> > Even git-clean(1) requires either --force or --interactive because it's too\n> > much risky to begin with.\n> > \n> > If we think Git as a FileSystem, its rm should only care about its tracked file. I\n> > prefer to just rm(1) instead of \"git-rm -u\".\n>\n"}]}