# Support for an interactive confirmation prompt when users can possibly lose their work like some UNIX commands

6 messages from 2019-08-27 to 2019-08-28. Participants: Vipul, Jeff King, Pratyush Yadav, Duy Nguyen.
Thread: https://gitlist.dev/t/51756

## Vipul, 2019-08-27 09:53

Subject: Support for an interactive confirmation prompt when users can possibly lose their work like some UNIX commands
Message-ID: <c1136131-0a9e-9dbb-3ad7-495ac96c1ef0@disroot.org>
URL: https://gitlist.dev/e/c1136131-0a9e-9dbb-3ad7-495ac96c1ef0%40disroot.org

```
Hi,

Sometimes, I messed-up with git repository and lost works due
carelessness. This includes reset a branch instead of other, drop the
stash etc by mistake. I wonder, is there way to a get an interactive
confirmation prompt (which ask for yes/no option) before executing those
commands when users can possibly lose their work? Like, some UNIX
commands have support for an interactive prompt (like 'rm -i', 'mv -i',
'cp -i', etc) for ex: before deleting and overwriting a file a
confirmation is prompt and asking for users permission.
	If there would no such feature available in git, so how do other people
avoid these kind of mistakes? Obviously, one them would be recheck the
command carefully before executing it and repo status but, I think
sometimes people also do these kind of mistakes. For now, to minimize
some of these kind problems I've modified my bash shell prompt to show
all kind information related to a git repository by sourcing
"git-prompt" script (provided with git package) and turn on all of flags
provided by it which significantly increase my productivity and less
mistakes than earlier. But, anything else I can do to avoid these kind
of mistakes at first place or increase my productivity (it includes
adopting some best practices, using some command line tools etc).
  	I searched it on the Internet and found that there are many GUI tools
available which help with these problems but don't want to use GUI tools
because most of time I work in command line environment and love using
command line tool than GUI one.

Any help would be greatly appreciated. Thanks.

PS: Sometimes, I would recover my work by seeking some help mostly on
#git IRC but, it would be better avoid this kind of mess at first place.

Cheers,
Vipul


```

## Jeff King, 2019-08-27 19:05

Subject: Re: Support for an interactive confirmation prompt when users can possibly lose their work like some UNIX commands
Message-ID: <20190827190509.GB3150@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20190827190509.GB3150%40sigill.intra.peff.net
In-Reply-To: <c1136131-0a9e-9dbb-3ad7-495ac96c1ef0@disroot.org>

```
On Tue, Aug 27, 2019 at 09:53:30AM +0000, Vipul wrote:

> Sometimes, I messed-up with git repository and lost works due
> carelessness. This includes reset a branch instead of other, drop the
> stash etc by mistake. I wonder, is there way to a get an interactive
> confirmation prompt (which ask for yes/no option) before executing those
> commands when users can possibly lose their work? Like, some UNIX
> commands have support for an interactive prompt (like 'rm -i', 'mv -i',
> 'cp -i', etc) for ex: before deleting and overwriting a file a
> confirmation is prompt and asking for users permission.
> 	If there would no such feature available in git, so how do other people
> avoid these kind of mistakes?

The usual philosophy in Git is not to bother the user with
confirmations, but to allow recovery after a mistake.

If you've moved a branch pointer around (e.g., via "git branch -f" or
"git reset"), you can recover it from the reflog.

In the case of a mistakenly dropped stash, there's no reflog (the stash
list itself is implemented as a reflog!), but you can use "git fsck" to
generate a list of "dangling" commits. These are commits which are
unreferenced, but they hang around until at least the next git-gc run.

Note that there _are_ some commands which are not reversible: mostly
things that drop content from the working tree. So "git reset --hard" is
one, and "git clean" is another. There have been discussions and even
some patches about storing the lost in an "undo log", but nothing has
been merged.

-Peff

```

## Pratyush Yadav, 2019-08-27 22:22

Subject: Re: Support for an interactive confirmation prompt when users can possibly lose their work like some UNIX commands
Message-ID: <20190827222224.yypf3ydvsebxypb6@yadavpratyush.com>
URL: https://gitlist.dev/e/20190827222224.yypf3ydvsebxypb6%40yadavpratyush.com
In-Reply-To: <c1136131-0a9e-9dbb-3ad7-495ac96c1ef0@disroot.org>

```
On 27/08/19 09:53AM, Vipul wrote:
> Hi,
> 
> Sometimes, I messed-up with git repository and lost works due
> carelessness. This includes reset a branch instead of other, drop the
> stash etc by mistake. I wonder, is there way to a get an interactive
> confirmation prompt (which ask for yes/no option) before executing those
> commands when users can possibly lose their work? Like, some UNIX
> commands have support for an interactive prompt (like 'rm -i', 'mv -i',
> 'cp -i', etc) for ex: before deleting and overwriting a file a
> confirmation is prompt and asking for users permission.
> 	If there would no such feature available in git, so how do other people
> avoid these kind of mistakes? Obviously, one them would be recheck the
> command carefully before executing it and repo status but, I think
> sometimes people also do these kind of mistakes. For now, to minimize
> some of these kind problems I've modified my bash shell prompt to show
> all kind information related to a git repository by sourcing
> "git-prompt" script (provided with git package) and turn on all of flags
> provided by it which significantly increase my productivity and less
> mistakes than earlier. But, anything else I can do to avoid these kind
> of mistakes at first place or increase my productivity (it includes
> adopting some best practices, using some command line tools etc).
>   	I searched it on the Internet and found that there are many GUI tools
> available which help with these problems but don't want to use GUI tools
> because most of time I work in command line environment and love using
> command line tool than GUI one.
 
On top of Jeff's great answer, I'll add that I try to not keep my work 
local for too long. I usually push out changes, even when they are WIP, 
to a fork kept on a server somewhere (GitHub for my personal projects). 
This way, if I mess up something real bad, I can clone the repo from the 
server and recover my work, at least partially.

[snip]

-- 
Regards,
Pratyush Yadav

```

## Vipul, 2019-08-27 22:42

Subject: Re: Support for an interactive confirmation prompt when users can possibly lose their work like some UNIX commands
Message-ID: <664344cb-f9e4-d4fc-fd14-620e3e10157a@disroot.org>
URL: https://gitlist.dev/e/664344cb-f9e4-d4fc-fd14-620e3e10157a%40disroot.org
In-Reply-To: <20190827190509.GB3150@sigill.intra.peff.net>

```
Jeff King wrote:
> The usual philosophy in Git is not to bother the user with
> confirmations, but to allow recovery after a mistake.
> 

Well, always prompting for confirmation will be annoying for some people
specially who are mastered in git but, may be very useful feature for
beginner's to avoid them from making mistakes. May be, this feature will
be disabled by default and users have to set some config variable (like
other git-config variable for example help.autocorrect etc) in global
gitconfig file.

> If you've moved a branch pointer around (e.g., via "git branch -f" or
> "git reset"), you can recover it from the reflog.
> 

Recovery is not a problem, asking for help on #git IRC people will tell
you whether data is recoverable. If recoverable, they will even guide
you step-by-step. But, I think it would be good idea to not make these
kind of mistakes at first place. Ultimately, we as a developer want to
make software more user-friendly and usable for normal users.

> Note that there _are_ some commands which are not reversible: mostly
> things that drop content from the working tree. So "git reset --hard" is
> one, and "git clean" is another. There have been discussions and even
> some patches about storing the lost in an "undo log", but nothing has
> been merged.
>
Seems like a good idea. Are they ever gonna merge? If no, why? Or, it
will merge in next feature release.


```

## Jeff King, 2019-08-28 15:05

Subject: Re: Support for an interactive confirmation prompt when users can possibly lose their work like some UNIX commands
Message-ID: <20190828150530.GD14432@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20190828150530.GD14432%40sigill.intra.peff.net
In-Reply-To: <664344cb-f9e4-d4fc-fd14-620e3e10157a@disroot.org>

```
On Tue, Aug 27, 2019 at 10:42:03PM +0000, Vipul wrote:

> Jeff King wrote:
> > The usual philosophy in Git is not to bother the user with
> > confirmations, but to allow recovery after a mistake.
> > 
> 
> Well, always prompting for confirmation will be annoying for some people
> specially who are mastered in git but, may be very useful feature for
> beginner's to avoid them from making mistakes. May be, this feature will
> be disabled by default and users have to set some config variable (like
> other git-config variable for example help.autocorrect etc) in global
> gitconfig file.

Sure, I think there's an argument to be made for confirmations (though I
personally would not want them). I was just describing what Git has now.

> > Note that there _are_ some commands which are not reversible: mostly
> > things that drop content from the working tree. So "git reset --hard" is
> > one, and "git clean" is another. There have been discussions and even
> > some patches about storing the lost in an "undo log", but nothing has
> > been merged.
> >
> Seems like a good idea. Are they ever gonna merge? If no, why? Or, it
> will merge in next feature release.

I don't know the latest state. A quick search of the archive showed this
as the latest version:

  https://public-inbox.org/git/20181209104419.12639-1-pclouds@gmail.com/

-Peff

```

## Duy Nguyen, 2019-08-28 15:27

Subject: Re: Support for an interactive confirmation prompt when users can possibly lose their work like some UNIX commands
Message-ID: <CACsJy8CnaYqKSs7oCpCVSiVeferb9KJS6Fvu791BH8nBYKt6Jg@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8CnaYqKSs7oCpCVSiVeferb9KJS6Fvu791BH8nBYKt6Jg%40mail.gmail.com
In-Reply-To: <20190828150530.GD14432@sigill.intra.peff.net>

```
On Wed, Aug 28, 2019 at 10:05 PM Jeff King <peff@peff.net> wrote:
> > > Note that there _are_ some commands which are not reversible: mostly
> > > things that drop content from the working tree. So "git reset --hard" is
> > > one, and "git clean" is another. There have been discussions and even
> > > some patches about storing the lost in an "undo log", but nothing has
> > > been merged.
> > >
> > Seems like a good idea. Are they ever gonna merge? If no, why? Or, it
> > will merge in next feature release.

If people are interested in the backup-log thing below, they can
reuse/refine the work or the idea from that, but I'm not going to push
it (or anything else) for merging.

> I don't know the latest state. A quick search of the archive showed this
> as the latest version:
>
>   https://public-inbox.org/git/20181209104419.12639-1-pclouds@gmail.com/
-- 
Duy

```
