threads / discuss / 42785

Fwd: git rm

Subject: Fwd: git rm

## tl;dr

7 messages between Jul 5, 2016 and Jul 10, 2016.

replies: 6people: 3as markdown or json

Peter· Jul 5, 2016, 21:55 UTC · lore
Greetings to the community of this wonderful piece of software!

I am a lightweigt git user so by all means not a reference, but I was wondering why exactly does "git rm" also delete the file (remove it from the working tree). I see it as an unintended behaviour as git is written in a way that it preserves the most data. Usually git commands are very basic and the usual workflow requires more consecutive commands, it even has its own shell. But "git rm" does everything in one step even though there are lots of scenarios where the file should be kept. I am aware of the "git rm --cache" command, but from my perspective "git rm --delete" is the one that is needed...

GUI users and some CLI users (by using trash-put or similar tool) also use trash before removing the file completely. Does "git rm" support freedesktop.org trash specification?

Thank you for your answers in advance, Peter

Andreas Schwab· Jul 6, 2016, 16:42 UTC · re: Peter · lore

Re: Fwd: git rm

Peter <peter.mx@gmail.com> writes:
> I am a lightweigt git user so by all means not a reference, but I was
> wondering why exactly does "git rm" also delete the file (remove it
> from the working tree). I see it as an unintended behaviour as git is
> written in a way that it preserves the most data.

The data is still preserved. You can restore it with "git checkout HEAD <file>".

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Jeff King· Jul 7, 2016, 03:35 UTC · re: Andreas Schwab · lore

Re: Fwd: git rm

On Wed, Jul 06, 2016 at 06:42:19PM +0200, Andreas Schwab wrote:
Show 9 quoted lines
> Peter <peter.mx@gmail.com> writes:
> 
> > I am a lightweigt git user so by all means not a reference, but I was
> > wondering why exactly does "git rm" also delete the file (remove it
> > from the working tree). I see it as an unintended behaviour as git is
> > written in a way that it preserves the most data.
> 
> The data is still preserved.  You can restore it with "git checkout HEAD
> <file>".

Assuming the file is present in HEAD, of course. But if it is not, then git should (and does) complain and ask for "-f".

-Peff
Peter· Jul 10, 2016, 08:38 UTC · re: Jeff King · lore

Re: Fwd: git rm

So if I do:

touch abc git add abc

And after that I do:
git rm abc

Can you agree that there is an asymmetry of two commands vs. one? Git add only touches the files in .git/ and git rm ALSO affects the working tree...

Is "git rm" or "git rm --cache" used more often in practice?
Peter
On 7 July 2016 at 05:35, Jeff King <peff@peff.net> wrote:
Show 16 quoted lines
> On Wed, Jul 06, 2016 at 06:42:19PM +0200, Andreas Schwab wrote:
>
>> Peter <peter.mx@gmail.com> writes:
>>
>> > I am a lightweigt git user so by all means not a reference, but I was
>> > wondering why exactly does "git rm" also delete the file (remove it
>> > from the working tree). I see it as an unintended behaviour as git is
>> > written in a way that it preserves the most data.
>>
>> The data is still preserved.  You can restore it with "git checkout HEAD
>> <file>".
>
> Assuming the file is present in HEAD, of course. But if it is not, then
> git should (and does) complain and ask for "-f".
>
> -Peff
Andreas Schwab· Jul 10, 2016, 10:57 UTC · re: Peter · lore

Re: Fwd: git rm

Peter <peter.mx@gmail.com> writes:
Show 9 quoted lines
> So if I do:
>
> touch abc
> git add abc
>
>
> And after that I do:
>
> git rm abc
error: the following file has changes staged in the index:
    abc
(use --cached to keep the file, or -f to force removal)
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Peter· Jul 10, 2016, 12:23 UTC · re: Andreas Schwab · lore

Re: Fwd: git rm

Ah, ok, I see now. But are there any other situations where the "-f" switch is not needed?

Peter
On 10 July 2016 at 12:57, Andreas Schwab <schwab@linux-m68k.org> wrote:
Show 21 quoted lines
> Peter <peter.mx@gmail.com> writes:
>
>> So if I do:
>>
>> touch abc
>> git add abc
>>
>>
>> And after that I do:
>>
>> git rm abc
> error: the following file has changes staged in the index:
>     abc
> (use --cached to keep the file, or -f to force removal)
>
> Andreas.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
Andreas Schwab· Jul 10, 2016, 12:45 UTC · re: Peter · lore

Re: Fwd: git rm

Peter <peter.mx@gmail.com> writes:
> Ah, ok, I see now. But are there any other situations where the "-f"
> switch is not needed?
When the file is unmodified and matches the index.
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

← back to recent threads