git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [Feature- Request] Option to commit after checking out branch command is made
@ 2017-11-15 15:27 Ninivaggi Mattia
  2017-11-16  0:19 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Ninivaggi Mattia @ 2017-11-15 15:27 UTC (permalink / raw)
  To: git@vger.kernel.org

Hey guys

Sometimes I tend to forget to commit changes before I checkout another branch and the following scenario happens (via cli on windows [with git bash]):

1. I checkout a branch, without having commited first
    > git checkout dev
2. I get this error message:
    > error: Your local changes to the following files would be overwritten by checkout:
    > // List of files
    > // ..
    > //
    > Please commit your changes or stash them before you switch branches.

But I would rather prefer a scenario like this:

1. I checkout a branch, without having commited first
    > git checkout dev
2. I get a message like this:
    > Your local changes to the following files would be overwritten by checkout:
    > // List of files
    > // ..
    > //
    > Would you want to commit first? (y/n))

IF y --> prompt for commit message and commit automatically
IF n --> display error message: "Please commit your changes or stash them before you switch branches"

This would be a faster/ more productive way to handle this error.

I think it wont be a big challenge, you just should put a message in the cli-tool when this error occurs and call the commit functionality if "y" is pressed. If you'd like I'll even consider doing it myself. If you have some documentation or some tipps on where to look for it.

Cheers

Ninivaggi Mattia

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

* Re: [Feature- Request] Option to commit after checking out branch command is made
  2017-11-15 15:27 [Feature- Request] Option to commit after checking out branch command is made Ninivaggi Mattia
@ 2017-11-16  0:19 ` Junio C Hamano
  2017-11-16 11:19   ` Ninivaggi Mattia
       [not found]   ` <CAGe7hXBPWvjaKZtz-Zn1az0HrCx=OpxGsghVJhLOBKMu3NJ2zA@mail.gmail.com>
  0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2017-11-16  0:19 UTC (permalink / raw)
  To: Ninivaggi Mattia; +Cc: git@vger.kernel.org

Ninivaggi Mattia <mattia.ninivaggi@helsana.ch> writes:

> 1. I checkout a branch, without having commited first
>     > git checkout dev
> 2. I get this error message:
>     > error: Your local changes to the following files would be overwritten by checkout:
>     > // List of files
>     > // ..
>     > //
>     > Please commit your changes or stash them before you switch branches.
>
> But I would rather prefer a scenario like this:
> ...
> 1. I checkout a branch, without having commited first
>     > git checkout dev
> 2. I get a message like this:
>     > Your local changes to the following files would be overwritten by checkout:
>     > // List of files
>     > // ..
>     > //
>     > Would you want to commit first? (y/n))
>
> IF y --> prompt for commit message and commit automatically

I do not think you want to do this for a few reasons.

 * The "please commit or stash" is merely a suggestion whose primary
   purpose is to silence clueless newbies who would have complained
   "Git said 'error: ... overwritten by checkout' and I do not know
   what to do next; the error message is so unhelpful" otherwise.
   Majority of the time when I see this message, it is because I
   forgot that I was in the middle of doing something (meaning: I am
   far from finished with the changes I was working on), and I would
   not be ready to commit.  I'd rather keep working to get the work
   into a more reasonable shape before committing, or stash the
   changes first if the task I wanted to do on that "dev" branch is
   more urgent and what I was in the middle of doing is lower
   priority.  

   Because of this, I would expect many users (including the ones
   who are right now newbies but will have gained experience to
   become experts in the future) to appreciate "stash before switch"
   a lot more than "commit first before switch".

 * People write scripts that use "git checkout" to switch branches,
   and they rely on the command to fail in this situation, instead
   of going interactive and gets stuck waiting for an input (which
   may never come).  Because of this, the updated behaviour you
   propose must never be the default, and at least must be protected
   behind a flag, something like "git checkout --autostash dev" (or
   "--autocommit", if you insist).  With that, you could do

	[alias]
		co = checkout --autostash

   and train your fingers to say "git co dev".

Of course, you can have a "git-co" script on your $PATH, which runs
"git checkout $1", lets it fail just like it does now, and then does
"git commit", if you really want the behaviour.  Again, you can then
use "git co dev" and you do not have to worry about breaking
people's scripts that depends on "git checkout" to fail without
going interactive.

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

* RE: [Feature- Request] Option to commit after checking out branch command is made
  2017-11-16  0:19 ` Junio C Hamano
@ 2017-11-16 11:19   ` Ninivaggi Mattia
       [not found]   ` <CAGe7hXBPWvjaKZtz-Zn1az0HrCx=OpxGsghVJhLOBKMu3NJ2zA@mail.gmail.com>
  1 sibling, 0 replies; 4+ messages in thread
From: Ninivaggi Mattia @ 2017-11-16 11:19 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org

I like the --autostash flag. 
But actually you just could write an alias co="git stash && git checkout" and use co dev for the same purpose, rendering the change irrelevant.

-----Original Message-----
From: Junio C Hamano [mailto:gitster@pobox.com] 
Sent: Thursday, November 16, 2017 1:20 AM
To: Ninivaggi Mattia
Cc: git@vger.kernel.org
Subject: Re: [Feature- Request] Option to commit after checking out branch command is made

Ninivaggi Mattia <mattia.ninivaggi@helsana.ch> writes:

> 1. I checkout a branch, without having commited first
>     > git checkout dev
> 2. I get this error message:
>     > error: Your local changes to the following files would be overwritten by checkout:
>     > // List of files
>     > // ..
>     > //
>     > Please commit your changes or stash them before you switch branches.
>
> But I would rather prefer a scenario like this:
> ...
> 1. I checkout a branch, without having commited first
>     > git checkout dev
> 2. I get a message like this:
>     > Your local changes to the following files would be overwritten by checkout:
>     > // List of files
>     > // ..
>     > //
>     > Would you want to commit first? (y/n))
>
> IF y --> prompt for commit message and commit automatically

I do not think you want to do this for a few reasons.

 * The "please commit or stash" is merely a suggestion whose primary
   purpose is to silence clueless newbies who would have complained
   "Git said 'error: ... overwritten by checkout' and I do not know
   what to do next; the error message is so unhelpful" otherwise.
   Majority of the time when I see this message, it is because I
   forgot that I was in the middle of doing something (meaning: I am
   far from finished with the changes I was working on), and I would
   not be ready to commit.  I'd rather keep working to get the work
   into a more reasonable shape before committing, or stash the
   changes first if the task I wanted to do on that "dev" branch is
   more urgent and what I was in the middle of doing is lower
   priority.  

   Because of this, I would expect many users (including the ones
   who are right now newbies but will have gained experience to
   become experts in the future) to appreciate "stash before switch"
   a lot more than "commit first before switch".

 * People write scripts that use "git checkout" to switch branches,
   and they rely on the command to fail in this situation, instead
   of going interactive and gets stuck waiting for an input (which
   may never come).  Because of this, the updated behaviour you
   propose must never be the default, and at least must be protected
   behind a flag, something like "git checkout --autostash dev" (or
   "--autocommit", if you insist).  With that, you could do

	[alias]
		co = checkout --autostash

   and train your fingers to say "git co dev".

Of course, you can have a "git-co" script on your $PATH, which runs "git checkout $1", lets it fail just like it does now, and then does "git commit", if you really want the behaviour.  Again, you can then use "git co dev" and you do not have to worry about breaking people's scripts that depends on "git checkout" to fail without going interactive.

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

* Fwd: [Feature- Request] Option to commit after checking out branch command is made
       [not found]   ` <CAGe7hXBPWvjaKZtz-Zn1az0HrCx=OpxGsghVJhLOBKMu3NJ2zA@mail.gmail.com>
@ 2019-06-03  8:44     ` David Eisner
  0 siblings, 0 replies; 4+ messages in thread
From: David Eisner @ 2019-06-03  8:44 UTC (permalink / raw)
  To: git

Hi all

Interesting discussion.

Though it's a pretty distant memory now, this "forgot to commit"
scenario was really frequent for me when I started using git. Then I'd
run commit and forget that it's split (from an outsider's perspective)
into add and then commit. I like the design of git, trees, index, etc.
now that I get it, but being kicked from one command to another with
an error message which may or may not tell me which command I should
have used is not fun.

Surely if it's an interactive "commit/stash/cancel" prompt, it could
default to cancel for non-interactive settings. If you're running a
script interactively that just does "git commit" and ignores the
output, the prompt would be fine. If you're running a script in a
non-interactive way, piping the command within the script, even just
to logs, etc. the prompt will not appear, just like with log or diff,
which do not use a pager in non-interactive contexts.

Generally, I think that prompting by default instead of warning and
quitting is a really good way to go. It more gently initiates the new
user, while still giving the option to quit and deal with the issue
another way. Seasoned users should be able to disable individual
prompts or all using options. Scripting should be a secondary
consideration for porcelain, because you can build more reliable
scripts by either using porcelain or being more explicit with
arguments and options. For example, in a script, it would be better to
specify the remote and branches for a push, rather than using
defaults.

Autostash/autocommit options would be great, if they also have "git
config checkout.autostash/autocommit" and --no-autostash/autocommit
and are set to prompt by default, or perhaps one autostash option that
can be set to false/stash/commit/prompt.

Yes, you could do this with scripting over the top of the existing
commands, but the best experience for new users should be available
out of the box, not by writing scripts.

On Thu, 16 Nov 2017 at 01:07, Junio C Hamano <gitster@pobox.com> wrote:
>
> Ninivaggi Mattia <mattia.ninivaggi@helsana.ch> writes:
>
> > 1. I checkout a branch, without having commited first
> >     > git checkout dev
> > 2. I get this error message:
> >     > error: Your local changes to the following files would be overwritten by checkout:
> >     > // List of files
> >     > // ..
> >     > //
> >     > Please commit your changes or stash them before you switch branches.
> >
> > But I would rather prefer a scenario like this:
> > ...
> > 1. I checkout a branch, without having commited first
> >     > git checkout dev
> > 2. I get a message like this:
> >     > Your local changes to the following files would be overwritten by checkout:
> >     > // List of files
> >     > // ..
> >     > //
> >     > Would you want to commit first? (y/n))
> >
> > IF y --> prompt for commit message and commit automatically
>
> I do not think you want to do this for a few reasons.
>
>  * The "please commit or stash" is merely a suggestion whose primary
>    purpose is to silence clueless newbies who would have complained
>    "Git said 'error: ... overwritten by checkout' and I do not know
>    what to do next; the error message is so unhelpful" otherwise.
>    Majority of the time when I see this message, it is because I
>    forgot that I was in the middle of doing something (meaning: I am
>    far from finished with the changes I was working on), and I would
>    not be ready to commit.  I'd rather keep working to get the work
>    into a more reasonable shape before committing, or stash the
>    changes first if the task I wanted to do on that "dev" branch is
>    more urgent and what I was in the middle of doing is lower
>    priority.
>
>    Because of this, I would expect many users (including the ones
>    who are right now newbies but will have gained experience to
>    become experts in the future) to appreciate "stash before switch"
>    a lot more than "commit first before switch".
>
>  * People write scripts that use "git checkout" to switch branches,
>    and they rely on the command to fail in this situation, instead
>    of going interactive and gets stuck waiting for an input (which
>    may never come).  Because of this, the updated behaviour you
>    propose must never be the default, and at least must be protected
>    behind a flag, something like "git checkout --autostash dev" (or
>    "--autocommit", if you insist).  With that, you could do
>
>         [alias]
>                 co = checkout --autostash
>
>    and train your fingers to say "git co dev".
>
> Of course, you can have a "git-co" script on your $PATH, which runs
> "git checkout $1", lets it fail just like it does now, and then does
> "git commit", if you really want the behaviour.  Again, you can then
> use "git co dev" and you do not have to worry about breaking
> people's scripts that depends on "git checkout" to fail without
> going interactive.

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

end of thread, other threads:[~2019-06-03  8:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-15 15:27 [Feature- Request] Option to commit after checking out branch command is made Ninivaggi Mattia
2017-11-16  0:19 ` Junio C Hamano
2017-11-16 11:19   ` Ninivaggi Mattia
     [not found]   ` <CAGe7hXBPWvjaKZtz-Zn1az0HrCx=OpxGsghVJhLOBKMu3NJ2zA@mail.gmail.com>
2019-06-03  8:44     ` Fwd: " David Eisner

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).