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

Re: A Basic Git Question About File Tracking [ANSWERED]

From
Jon Forrest <nobozo@gmail.com>
Date
Oct 9, 2011, 02:42 UTC
Message-ID
<4E910A14.7040801@gmail.com>
In-Reply-To
<m3ipnz0xri.fsf@localhost.localdomain>
On 10/8/2011 6:17 PM, Jakub Narebski wrote:
> You seem to be under [false] impression that git commit is about
> _changes_ / _changeset_.
This is correct. The Pro Git book says:

"You stage these modified files and then commit all your staged changes"

Plus, even "git status" tells me

$ git status # On branch master # Changes to be committed:

But I see my error. Below is what I hope is a clear explanation of what I didn't understand. It presumes that the reader understands the git objects model. Please let me know if anything is incorrect. ---------- When you "git add" a file two things happen:

1) The file is copied to the git objects tree.
This location where the file is copied depends
on the hash of the file's content.
2) An entry for the file is added to the git index.
This entry includes the same hash that was mentioned
in #1.

A tracked file has an entry in the git index file. A copy of the file also exists in the objects tree.

When you run 'git status', git computes the hash of every file in your working directory and looks up each file in the index. If the file isn't found then the file is shown as untracked.

When you do a commit, the hash values of everything in the index are copied into a tree object. The hash value of the tree object is then placed in a commit object. No copies of tracked files in the working directory are made at commit time. This is because the files were already copied into the objects tree when 'git add' was run. This is one reason why git commits are so fast.

-----
How's that?
Thanks to everyone for sticking with me on this.
Jon
Previous: Jakub NarebskiNext: Jakub Narebski
Message 7 of 9 in “A Basic Git Question About File Tracking”
  1. Jon ForrestOct 4, 2011
  2. Jonathan NiederOct 4, 2011
  3. Jon ForrestOct 4, 2011
  4. Jonathan NiederOct 4, 2011
  5. Jon ForrestOct 9, 2011
  6. Jakub NarebskiOct 9, 2011
  7. Jon ForrestOct 9, 2011
  8. Jakub NarebskiOct 9, 2011
  9. Scott ChaconOct 9, 2011

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.