Web lists-archives.com

Re: "git checkout" safety feature




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@xxxxxxxxxxxxxx/

for example.

-Peff