git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Add warning when there are changes in the index and using -a with git commit

From
Eli Barzilay <eli@barzilay.org>
Date
Apr 21, 2010, 21:31 UTC
Message-ID
<19407.28316.959251.348645@winooski.ccs.neu.edu>
In-Reply-To
<q2pfabb9a1e1004211421q80d273ady11f4621284522c46@mail.gmail.com>
On Apr 21, Sverre Rabbelier wrote:
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 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!
Previous: Sverre RabbelierNext: Wincent Colaiuta
Message 3 of 5 in “Add warning when there are changes in the index and using -a with git commit”
  1. Sylvain RabotApr 21, 2010
  2. Sverre RabbelierApr 21, 2010
  3. Eli BarzilayApr 21, 2010
  4. Wincent ColaiutaApr 21, 2010
  5. Sylvain RabotApr 21, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.