{"thread":{"id":"53837","subject":"\"git rm\" could be safer and have a better help msg","startedAt":"2020-07-10T12:26:12Z","lastAt":"2020-07-10T22:43:38Z","messageCount":6,"participants":["Tom Browder","Andreas Schwab","Aaron Schrab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"401339","messageId":"CAFMGiz97fcw_nvaa=Xo-roTtB1o25qO06=PHGSrBzv4k_zGqaw@mail.gmail.com","threadId":"53837","inReplyTo":null,"subject":"\"git rm\" could be safer and have a better help msg","fromName":"Tom Browder","fromEmail":"tom.browder@gmail.com","sentAt":"2020-07-10T12:25:29Z","receivedAt":"2020-07-10T12:26:12Z","isPatch":false,"sender":{"key":"tom.browder@gmail.com","avatar":"https://gravatar.com/avatar/dfedb5a3ca4293808d6aa886175c9eac50d162502098db3714f1e678e551de2b?d=mp&s=160"},"body":"I often need to remove a file from Git but leave it as is, changed or not.\nThe only safe way to do that as far as I know is:\n\n    $ git rm -f --cached myfile   # many thanks to @jast on IRC #git\n\nThe \"git help rm\" command yields copious information but nowhere can I find\na clear statement about safely removing a modified file from Git without\nremoving it from the file system.\n\nI am going to create an alias to help me, but I believe the brute force\nremoval should be a different option, say, '-F' ('--Force'), and the\nexisting '-f' ('--force') ought to be safe operations as far as the file\nsystem is concerned.\n\nBest regards,\n\n-Tom\n"},{"id":"401340","messageId":"878sfr1rdm.fsf@igel.home","threadId":"53837","inReplyTo":"CAFMGiz97fcw_nvaa=Xo-roTtB1o25qO06=PHGSrBzv4k_zGqaw@mail.gmail.com","subject":"Re: \"git rm\" could be safer and have a better help msg","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2020-07-10T12:33:41Z","receivedAt":"2020-07-10T12:33:46Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Jul 10 2020, Tom Browder wrote:\n\n> I often need to remove a file from Git but leave it as is, changed or not.\n> The only safe way to do that as far as I know is:\n>\n>     $ git rm -f --cached myfile   # many thanks to @jast on IRC #git\n\nWhy do you need -f?\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"},{"id":"401342","messageId":"CAFMGiz8+pjskPpPqVgQUevKdWgxPvCKBcmx-07E2yizDqhm9mg@mail.gmail.com","threadId":"53837","inReplyTo":"878sfr1rdm.fsf@igel.home","subject":"Re: \"git rm\" could be safer and have a better help msg","fromName":"Tom Browder","fromEmail":"tom.browder@gmail.com","sentAt":"2020-07-10T13:14:08Z","receivedAt":"2020-07-10T13:14:49Z","isPatch":false,"sender":{"key":"tom.browder@gmail.com","avatar":"https://gravatar.com/avatar/dfedb5a3ca4293808d6aa886175c9eac50d162502098db3714f1e678e551de2b?d=mp&s=160"},"body":"On Fri, Jul 10, 2020 at 7:33 AM Andreas Schwab <schwab@linux-m68k.org> wrote:\n> >     $ git rm -f --cached myfile   # many thanks to @jast on IRC #git\n> Why do you need -f?\n\nIf the existing file has been modified, with 'rm'  the '--cached'\noption doesn't remove it from Git\nunless one uses the '-f' option with it.\n\n\n-Tom\n"},{"id":"401344","messageId":"874kqf1n65.fsf@igel.home","threadId":"53837","inReplyTo":"CAFMGiz8+pjskPpPqVgQUevKdWgxPvCKBcmx-07E2yizDqhm9mg@mail.gmail.com","subject":"Re: \"git rm\" could be safer and have a better help msg","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2020-07-10T14:04:34Z","receivedAt":"2020-07-10T14:04:38Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Jul 10 2020, Tom Browder wrote:\n\n> If the existing file has been modified, with 'rm'  the '--cached'\n> option doesn't remove it from Git\n> unless one uses the '-f' option with it.\n\nIt doesn't?  Worksforme.\n\n$ echo >> zlib.c\n$ git status\nOn branch master\nYour branch is up to date with 'origin/master'.\n\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        modified:   zlib.c\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\n$ git rm --cached zlib.c\nrm 'zlib.c'\n$ git status\nOn branch master\nYour branch is up to date with 'origin/master'.\n\nChanges to be committed:\n  (use \"git restore --staged <file>...\" to unstage)\n        deleted:    zlib.c\n\nUntracked files:\n  (use \"git add <file>...\" to include in what will be committed)\n        zlib.c\n\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"},{"id":"401348","messageId":"CAFMGiz_5Jop2nVXJuMOR7NT9gKEygueic1m5-yw8BrkDgZ-O3w@mail.gmail.com","threadId":"53837","inReplyTo":"874kqf1n65.fsf@igel.home","subject":"Re: \"git rm\" could be safer and have a better help msg","fromName":"Tom Browder","fromEmail":"tom.browder@gmail.com","sentAt":"2020-07-10T16:31:35Z","receivedAt":"2020-07-10T16:32:15Z","isPatch":false,"sender":{"key":"tom.browder@gmail.com","avatar":"https://gravatar.com/avatar/dfedb5a3ca4293808d6aa886175c9eac50d162502098db3714f1e678e551de2b?d=mp&s=160"},"body":"On Fri, Jul 10, 2020 at 9:04 AM Andreas Schwab <schwab@linux-m68k.org> wrote:\n> On Jul 10 2020, Tom Browder wrote:\n> > If the existing file has been modified, with 'rm'  the '--cached'\n> > option doesn't remove it from Git\n> > unless one uses the '-f' option with it.\n>\n> It doesn't?  Worksforme.\n\nThanks, Andreas, that does indeed work. I must have done something\nwrong, so I'll pay closer attention to what I'm doing.\n\nBest regards,\n\n-Tom\n"},{"id":"401390","messageId":"20200710224335.GB1346@pug.qqx.org","threadId":"53837","inReplyTo":"874kqf1n65.fsf@igel.home","subject":"Re: \"git rm\" could be safer and have a better help msg","fromName":"Aaron Schrab","fromEmail":"aaron@schrab.com","sentAt":"2020-07-10T22:43:35Z","receivedAt":"2020-07-10T22:43:38Z","isPatch":false,"sender":{"key":"aaron@schrab.com","avatar":"https://avatars.githubusercontent.com/u/39620?v=4"},"body":"At 16:04 +0200 10 Jul 2020, Andreas Schwab <schwab@linux-m68k.org> wrote:\n>On Jul 10 2020, Tom Browder wrote:\n>\n>> If the existing file has been modified, with 'rm'  the '--cached'\n>> option doesn't remove it from Git\n>> unless one uses the '-f' option with it.\n>\n>It doesn't?  Worksforme.\n\nIt needs to be forced iff the cached version doesn't match either what's \nin HEAD or on the file system. So when there's potential to lose work \nsimilar to other situations which require specifying a force option.\n\n     $ git rm --cached a\n     error: the following file has staged content different from both the\n     file and the HEAD:\n         a\n     (use -f to force removal)\n"}]}