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

Re: Git commit won't add an untracked file given on the command line

From
Miles Bader <miles@gnu.org>
Date
Nov 20, 2008, 05:06 UTC
Message-ID
<buowsez56kv.fsf@dhapc248.dev.necel.com>
In-Reply-To
<alpine.DEB.1.00.0811191036340.30769@pacific.mpi-cbg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 12 quoted lines
>> I use the staging area a lot, so I think I have a pretty clear idea of 
>> what it's "about", but I also often use "commit FILE" or "commit -a" for 
>> simple cases; even when splitting a change into multiple commits, it's 
>> often more convenient to do "commit FILE..." instead of "add FILE; 
>> commit".
>
> What I meant was this: the "commit <file>" paradigm is not what you should 
> do most of the time.  In order to work with the staging area efficiently, 
> you should make staging and committing two separate steps.
>
> So my point is this: stage first, verify, then commit.  That saves you a 
> lot of embarrassment.

You seem to be saying that you think that using staging area explicitly is necessary or somehow "more efficient" for making good commits, but on the face of it, that's simply not true.

I'm extremely careful about committing clean changes, and do a lot of testing and pre-commit diffing. For complex changes which need to be split, the staging area is indeed a very useful tool, and I'm very glad git has it -- but it's hardly necessary for _all_ commits, and my experience is that in practice, many commits are indeed the simple sort which for which it's superfluous. My goal is not to "work with the staging area efficiently", it's to "make good/clean/tested commits, efficiently".

Obviously this depends on work style, and subject matter. Sometimes one _needs_ to make biggish changes and split them for commiting, and some people like to use that work style even when it's not strictly necessary. Other times, changes are more obviously independent, and can be done, tested, and commited in a serial fashion without any splitting.

Perhaps, given your work style or the type of work you, you use the staging area 99% of the time. For your case, maybe any git features which bypass the staging area are simply unneeded complexity. However, my own experience suggests that this is not universally true. I'd say I use the staging area for maybe 50% of commits.

One of the nice thing about git is the way that it tries to cater to multiple work styles, so it seems wrong to reject a useful feature simply because you want to "encourage" people to use your preferred work style, when that work style is not obviously better. [Of course there can be other good reasons to reject this feature -- maybe it's too dangerous or mucks up the code.]

> I regularly encounter people who never call "git diff --cached" before 
> committing, and guess who introduces all kinds of debug statements and 
> other cruft into their commits?  Exactly.

[I'm not sure what the point of that was... for the record, no I'm not one of "those people". When I use the staging area, I use "git diff --cached"; when I don't use the staging area, I "git diff" instead...]

-Miles
-- 
Bacchus, n. A convenient deity invented by the ancients as an excuse for
getting drunk.
Previous: Johannes SchindelinNext: Junio C Hamano
Message 9 of 22 in “Git commit won't add an untracked file given on the command line”
  1. Mark BurtonNov 18, 2008
  2. Francis GaliegueNov 18, 2008
  3. Mark BurtonNov 18, 2008
  4. Johannes SchindelinNov 19, 2008
  5. Miles BaderNov 19, 2008
  6. Johannes SchindelinNov 19, 2008
  7. Miles BaderNov 19, 2008
  8. Johannes SchindelinNov 19, 2008
  9. Miles BaderNov 20, 2008
  10. Junio C HamanoNov 19, 2008
  11. Mark BurtonNov 19, 2008
  12. Johannes SchindelinNov 19, 2008
  13. Junio C HamanoNov 19, 2008
  14. Mark BurtonNov 19, 2008
  15. Daniel BarkalowNov 19, 2008
  16. Junio C HamanoNov 19, 2008
  17. Mark BurtonNov 19, 2008
  18. Junio C HamanoNov 19, 2008
  19. Daniel BarkalowNov 19, 2008
  20. Junio C HamanoNov 20, 2008
  21. David AguilarNov 20, 2008
  22. Matthieu MoyNov 18, 2008

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.