In Pro Git the author says that Git staging is just a file storing which files go towards next commit. Then how does Git remember the contents of a file in staging area, even after that file is again modified in working directory?
E.g.
- edit myFile
- git add myFile
- edit myFile
Now, upon commit Git checks in the file as in step 2. How does it remember the contents of file in staging, if staging is just a file marking? Does it also store file contents, upon staging instead of just the file marking?
Yes, it must necessarily do so to allow you to diff the file in the working directory with the file in the index.
git adddoesn’t simply “mark files for commit”, it adds the content of the file to the index, so the content of the file can be added to the next commit. Content is all Git can track, that’s how it works: It tracks the content of files.