git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* "git checkout" safety feature
@ 2018-11-04 19:12 Matthias Urlichs
  2018-11-05  1:12 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Urlichs @ 2018-11-04 19:12 UTC (permalink / raw)
  To: git


[-- Attachment #1.1: Type: text/plain, Size: 363 bytes --]

Hi,

A recent discussion on LWN https://lwn.net/Articles/770642/ noted that
"git checkout <release> <file…>" does not warn if one if the files has
been modified locally, nor is there an option to do so.

IMHO that should be fixed, preferably by somebody who knows git's
internals well enough to do so in half an hour ;-)

-- 
-- Matthias Urlichs



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: "git checkout" safety feature
  2018-11-04 19:12 "git checkout" safety feature Matthias Urlichs
@ 2018-11-05  1:12 ` Junio C Hamano
  2018-11-05  6:24   ` Matthias Urlichs
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2018-11-05  1:12 UTC (permalink / raw)
  To: Matthias Urlichs; +Cc: git


Matthias Urlichs <matthias@urlichs.de> writes:

> A recent discussion on LWN https://lwn.net/Articles/770642/ noted that
> "git checkout <release> <file…>" does not warn if one if the files has
> been modified locally, nor is there an option to do so.
>
> IMHO that should be fixed, preferably by somebody who knows git's
> internals well enough to do so in half an hour ;-)

"git checkout <commit> <pathspec>" is a feature to overwrite local
changes.  It is what you use when you make a mess editing the files
and want to go back to a known state.  Why should that feature be
destroyed?


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

* Re: "git checkout" safety feature
  2018-11-05  1:12 ` Junio C Hamano
@ 2018-11-05  6:24   ` Matthias Urlichs
  2018-11-05  6:51     ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Urlichs @ 2018-11-05  6:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git


[-- Attachment #1.1: Type: text/plain, Size: 346 bytes --]

Hi,
> "git checkout <commit> <pathspec>" is a feature to overwrite local
> changes.  It is what you use when you make a mess editing the files
> and want to go back to a known state.  Why should that feature be
> destroyed?

Not destroyed, but optionally made finger-fumble-save – like "alias rm
rm -i".

-- 
-- Matthias Urlichs



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: "git checkout" safety feature
  2018-11-05  6:24   ` Matthias Urlichs
@ 2018-11-05  6:51     ` Jeff King
  2018-11-05 15:33       ` Duy Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2018-11-05  6:51 UTC (permalink / raw)
  To: Matthias Urlichs; +Cc: Junio C Hamano, git

On Mon, Nov 05, 2018 at 07:24:42AM +0100, Matthias Urlichs wrote:

> Hi,
> > "git checkout <commit> <pathspec>" is a feature to overwrite local
> > changes.  It is what you use when you make a mess editing the files
> > and want to go back to a known state.  Why should that feature be
> > destroyed?
> 
> Not destroyed, but optionally made finger-fumble-save – like "alias rm
> rm -i".

There are a couple of destructive commands left in Git (e.g., this one,
and "git reset --hard" is another). I didn't dig up archive references,
but the topic of safety valves has come up many times over the years.
The discussion usually ends with the notion that instead of warning
that the operation is destructive (because that gets annoying when its
purpose is to be destructive), we should make it possible to undo a
mistake.

So in this case, that would mean saving the working tree file to a blob
before we obliterate it.

See similar discussion in:

  https://public-inbox.org/git/CACsJy8C5QOLvg4pzy_pThQoyGh9ohdeVHXsuYwQHQypn3oBxkw@mail.gmail.com/

for example.

-Peff

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

* Re: "git checkout" safety feature
  2018-11-05  6:51     ` Jeff King
@ 2018-11-05 15:33       ` Duy Nguyen
  0 siblings, 0 replies; 5+ messages in thread
From: Duy Nguyen @ 2018-11-05 15:33 UTC (permalink / raw)
  To: Jeff King; +Cc: Matthias Urlichs, Junio C Hamano, Git Mailing List

On Mon, Nov 5, 2018 at 7:53 AM Jeff King <peff@peff.net> wrote:
>
> On Mon, Nov 05, 2018 at 07:24:42AM +0100, Matthias Urlichs wrote:
>
> > Hi,
> > > "git checkout <commit> <pathspec>" is a feature to overwrite local
> > > changes.  It is what you use when you make a mess editing the files
> > > and want to go back to a known state.  Why should that feature be
> > > destroyed?
> >
> > Not destroyed, but optionally made finger-fumble-save – like "alias rm
> > rm -i".
>
> There are a couple of destructive commands left in Git (e.g., this one,
> and "git reset --hard" is another). I didn't dig up archive references,
> but the topic of safety valves has come up many times over the years.
> The discussion usually ends with the notion that instead of warning
> that the operation is destructive (because that gets annoying when its
> purpose is to be destructive), we should make it possible to undo a
> mistake.
>
> So in this case, that would mean saving the working tree file to a blob
> before we obliterate it.
>
> See similar discussion in:
>
>   https://public-inbox.org/git/CACsJy8C5QOLvg4pzy_pThQoyGh9ohdeVHXsuYwQHQypn3oBxkw@mail.gmail.com/
>
> for example.

That work is still ongoing (slowly). I realized that reflog code was
buried deep in files-backend.c and would not make sense to reuse in
its current form. So I had to move the code to a common place, which
adds more work. But it will be coming! Hopefully before 2020 at my
usual development speed.

While we're at it, I've been running something with that "index
reflog" (no pruning) for a month with lots of "add -p" and the file
size is just 163KB, so the reflog format seems promising for this
purpose.
-- 
Duy

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

end of thread, other threads:[~2018-11-05 15:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-04 19:12 "git checkout" safety feature Matthias Urlichs
2018-11-05  1:12 ` Junio C Hamano
2018-11-05  6:24   ` Matthias Urlichs
2018-11-05  6:51     ` Jeff King
2018-11-05 15:33       ` Duy Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).