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

Re: [RFC] git-add update with all-0 object

From
Linus Torvalds <torvalds@osdl.org>
Date
Nov 30, 2006, 22:46 UTC
Message-ID
<Pine.LNX.4.64.0611301431420.3513@woody.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0611301634080.20138@iabervon.org>
On Thu, 30 Nov 2006, Daniel Barkalow wrote:
> 
> I think the more obvious behavior is to have it record the fact that you 
> want to have the path tracked, but require one of the usual updating 
> mechanisms to get a particular content into the index.

While this certainly matches the git model better than just automatically taking whatever state exist at commit time (you instead introduce it as a special "empty state" case), I don't think you really want it.

Why? 
Two reasons:
 - you're still left with all the same issues (ie you do need to use "git 
   commit -a" because that is simply fundamental, and if you don't, "git 
   commit" now causes an ERROR, which is just illogical - you just added 
   the data!)
   So it's simply better to just tell people "git add" adds the whole 
   state. Explain to them that git doesn't track "filenames", it tracks 
   state, and when you do a "git add", it really adds the _data_ and the 
   permissions too.
   Really, if you didn't come from years of broken SCM's, you'd think that 
   it's _natural_ that when you add a file for tracking, you add its 
   contents too. It's not that git is surprising or unnatural, it's that 
   CVS is.
 - you generally really don't want to see "git diff" show you the big diff 
   for a new creation. You only think you do, but trust me, you generally 
   don't. It's the same thing as with doing merges - keeping the 
   automerged state in the index is actually nice, because it means that 
   the default "git diff" can just shut the heck up about the things that 
   may be the _bulk_ of the change, but it's not the interesting part.

So I would suggest that if people are irritated with "git diff" for example not showing newly added files AT ALL, then the solution to that isn't that they should be added as "empty" or "all zeroes". We do have other state bits in the index already (we need them for marking things as being unmerged etc), and if the problem is that you want to see that you have a pending add, it's easy enough to have "git add" always set a bit saying "this file is new".

A normal "read tree object" would populate index entries with that bit cleared, and so it would be possible to have

	git add file.c
	git diff
show something like
	diff --git a/file.c b/file.c
	added file <mode> <sha1>

rather than show the whole big diff (which I _really_ don't think you want to see, and which is actually against the whole point, which is that you add _content_ to the index, and "git diff" will always show you the stuff that is _not_ added to the index yet).

(Of course, if you _also_ had changed it between the "git add" and the "git diff", you'd get both the "added file <mode> <sha1>" _and_ the diff that is the diff between the thing you added, and the status it has now).

So showing a real diff after "git add" would really be wrong. The index really is important. But if it's _only_ an issue of worrying about seeing added files at all, we can add a "people comfort" bit to do that.

(Quite frankly, I don't think it's worthwhile. I really think this is a documentation issue. Make people understand that "git add" adds the contents too, and that git never tracks filenames on their own at all).

So it is always going to be true that
	git add file
	echo New line >> file
	git commit

must commit the old contents of the file. That really _does_ follow from the whole "track contents" model. Anything that doesn't do this is fundamnetally broken, and has broken the notion of what "git add" means.

Previous: Nicolas PitreNext: Daniel Barkalow
Message 6 of 15 in “[RFC] git-add update with all-0 object”
  1. Daniel BarkalowNov 30, 2006
  2. Johannes SchindelinNov 30, 2006
  3. Nicolas PitreNov 30, 2006
  4. Jakub NarebskiNov 30, 2006
  5. Nicolas PitreNov 30, 2006
  6. Linus TorvaldsNov 30, 2006
  7. Daniel BarkalowDec 1, 2006
  8. Theodore TsoDec 1, 2006
  9. Junio C HamanoDec 1, 2006
  10. Jakub NarebskiDec 2, 2006
  11. Linus TorvaldsDec 1, 2006
  12. Daniel BarkalowDec 1, 2006
  13. Andy ParkinsDec 1, 2006
  14. Jakub NarebskiDec 2, 2006
  15. Jakub NarebskiDec 2, 2006

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.