* Re: Add warning when there are changes in the index and using -a with git commit
2010-04-21 21:21 ` Sverre Rabbelier
@ 2010-04-21 21:31 ` Eli Barzilay
2010-04-21 21:38 ` Wincent Colaiuta
1 sibling, 0 replies; 5+ messages in thread
From: Eli Barzilay @ 2010-04-21 21:31 UTC (permalink / raw)
To: Sverre Rabbelier; +Cc: Sylvain Rabot, git
On Apr 21, Sverre Rabbelier wrote:
> 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 recently wrote a very quick script that I think is much better at
doing what svn users expect, but doesn't get in the way of doing more
git-ish things when they learn more git in the future. IMO it works
much better than the frequent advice I've seen in many places to just
add `-a' to `git commit'. The only thing that this does is add "." if
there are no other paths mentioned as arguments. Looks like in this
case git will add all files in the current directory, and commit them
together with staged content in this directory -- which I think covers
everythint that svn does. I dropped this in my path as `git-ci':
#!/bin/sh
seen_path=no; for p; do if [ -e "$p" ]; then seen_path=yes; fi; done
if [ $seen_path = yes ]; then git commit "$@"; else git commit . "$@"; fi
(Disclaimer: naive check, so if someone uses "git ci -m ." it will get
confused. But it adds the "." in the beginning, so typos like
"git ci -m" don't get broken.)
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add warning when there are changes in the index and using -a with git commit
2010-04-21 21:21 ` Sverre Rabbelier
2010-04-21 21:31 ` Eli Barzilay
@ 2010-04-21 21:38 ` Wincent Colaiuta
2010-04-21 22:38 ` Sylvain Rabot
1 sibling, 1 reply; 5+ messages in thread
From: Wincent Colaiuta @ 2010-04-21 21:38 UTC (permalink / raw)
To: Sverre Rabbelier; +Cc: Sylvain Rabot, git
El 21/04/2010, a las 23:21, Sverre Rabbelier escribió:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread