All of lore.kernel.org
 help / color / mirror / Atom feed
* "git rm" could be safer and have a better help msg
@ 2020-07-10 12:25 Tom Browder
  2020-07-10 12:33 ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Browder @ 2020-07-10 12:25 UTC (permalink / raw)
  To: git

I often need to remove a file from Git but leave it as is, changed or not.
The only safe way to do that as far as I know is:

    $ git rm -f --cached myfile   # many thanks to @jast on IRC #git

The "git help rm" command yields copious information but nowhere can I find
a clear statement about safely removing a modified file from Git without
removing it from the file system.

I am going to create an alias to help me, but I believe the brute force
removal should be a different option, say, '-F' ('--Force'), and the
existing '-f' ('--force') ought to be safe operations as far as the file
system is concerned.

Best regards,

-Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "git rm" could be safer and have a better help msg
  2020-07-10 12:25 "git rm" could be safer and have a better help msg Tom Browder
@ 2020-07-10 12:33 ` Andreas Schwab
  2020-07-10 13:14   ` Tom Browder
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2020-07-10 12:33 UTC (permalink / raw)
  To: Tom Browder; +Cc: git

On Jul 10 2020, Tom Browder wrote:

> I often need to remove a file from Git but leave it as is, changed or not.
> The only safe way to do that as far as I know is:
>
>     $ git rm -f --cached myfile   # many thanks to @jast on IRC #git

Why do you need -f?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "git rm" could be safer and have a better help msg
  2020-07-10 12:33 ` Andreas Schwab
@ 2020-07-10 13:14   ` Tom Browder
  2020-07-10 14:04     ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Browder @ 2020-07-10 13:14 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: git

On Fri, Jul 10, 2020 at 7:33 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >     $ git rm -f --cached myfile   # many thanks to @jast on IRC #git
> Why do you need -f?

If the existing file has been modified, with 'rm'  the '--cached'
option doesn't remove it from Git
unless one uses the '-f' option with it.


-Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "git rm" could be safer and have a better help msg
  2020-07-10 13:14   ` Tom Browder
@ 2020-07-10 14:04     ` Andreas Schwab
  2020-07-10 16:31       ` Tom Browder
  2020-07-10 22:43       ` Aaron Schrab
  0 siblings, 2 replies; 6+ messages in thread
From: Andreas Schwab @ 2020-07-10 14:04 UTC (permalink / raw)
  To: Tom Browder; +Cc: git

On Jul 10 2020, Tom Browder wrote:

> If the existing file has been modified, with 'rm'  the '--cached'
> option doesn't remove it from Git
> unless one uses the '-f' option with it.

It doesn't?  Worksforme.

$ echo >> zlib.c
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   zlib.c

no changes added to commit (use "git add" and/or "git commit -a")
$ git rm --cached zlib.c
rm 'zlib.c'
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    zlib.c

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        zlib.c


Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "git rm" could be safer and have a better help msg
  2020-07-10 14:04     ` Andreas Schwab
@ 2020-07-10 16:31       ` Tom Browder
  2020-07-10 22:43       ` Aaron Schrab
  1 sibling, 0 replies; 6+ messages in thread
From: Tom Browder @ 2020-07-10 16:31 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: git

On Fri, Jul 10, 2020 at 9:04 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
> On Jul 10 2020, Tom Browder wrote:
> > If the existing file has been modified, with 'rm'  the '--cached'
> > option doesn't remove it from Git
> > unless one uses the '-f' option with it.
>
> It doesn't?  Worksforme.

Thanks, Andreas, that does indeed work. I must have done something
wrong, so I'll pay closer attention to what I'm doing.

Best regards,

-Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "git rm" could be safer and have a better help msg
  2020-07-10 14:04     ` Andreas Schwab
  2020-07-10 16:31       ` Tom Browder
@ 2020-07-10 22:43       ` Aaron Schrab
  1 sibling, 0 replies; 6+ messages in thread
From: Aaron Schrab @ 2020-07-10 22:43 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Tom Browder, git

At 16:04 +0200 10 Jul 2020, Andreas Schwab <schwab@linux-m68k.org> wrote:
>On Jul 10 2020, Tom Browder wrote:
>
>> If the existing file has been modified, with 'rm'  the '--cached'
>> option doesn't remove it from Git
>> unless one uses the '-f' option with it.
>
>It doesn't?  Worksforme.

It needs to be forced iff the cached version doesn't match either what's 
in HEAD or on the file system. So when there's potential to lose work 
similar to other situations which require specifying a force option.

     $ git rm --cached a
     error: the following file has staged content different from both the
     file and the HEAD:
         a
     (use -f to force removal)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-10 22:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10 12:25 "git rm" could be safer and have a better help msg Tom Browder
2020-07-10 12:33 ` Andreas Schwab
2020-07-10 13:14   ` Tom Browder
2020-07-10 14:04     ` Andreas Schwab
2020-07-10 16:31       ` Tom Browder
2020-07-10 22:43       ` Aaron Schrab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.