Re: Add warning when there are changes in the index and using -a with git commit
- From
Wincent Colaiuta <win@wincent.com>
- Date
- Apr 21, 2010, 21:38 UTC
- Message-ID
- <0CCBCCA0-8378-42A8-A925-F60AA09949DC@wincent.com>
- In-Reply-To
- <q2pfabb9a1e1004211421q80d273ady11f4621284522c46@mail.gmail.com>
El 21/04/2010, a las 23:21, Sverre Rabbelier escribió:
Show 11 quoted lines
> Heya, > > On Wed, Apr 21, 2010 at 22:20, Sylvain Rabot <sylvain@abstraction.fr> wrote: >> Many times I had the bad reflex of doing a git commit -as -m "blah >> blah" when I was willing to commit only things I had staged in the >> index. > > Me too, and I think I brought it up in the past and it was dismissed > as being too annoying, but I'm not sure. Either way, you can work > around it by creating your own 'git-co' wrapper that does the check > and use that instead of 'git commit'.
I think this is a tendency fostered by evil tutorials which start off by saying that people can use "git commit -a" in order to continue working in the same way they are used to from Subversion. (These tutorials do more harm than good, IMO. Counseling people to use "git commit -a" and live as though the index didn't exist is about the same as teaching newcomers to VIM that they should just stay in insert mode the whole time; it's encouraging bad habits that end up producing a limited awareness of and proficiency with the tool.)
I personally never make the mistake of accidentally including an "-a" in my "git commit" parameters, because for me "-a" is not something routine but actually quite the opposite: something extremely exceptional.
Without even really meaning to, I ended up training myself to only commit what's staged in the index, because early on I acquired the habit of always reviewing every single changed hunk by using "git add --patch" (in fact I use it so often that I've created an alias of "git patch" for it). There's no telling how many times this kind of last-minute hunk-by-hunk reviewing has saved me from committing bad code.
Cheers, Wincent