The git index allows us to specify the files that go into a new tree object - such a tree object is what any newly created commit object will point to.
I'm aware that using git add <filename> puts a file into the index so that a tree can be generated.
However, the index seems to store files even before they have been added to the index. After running the following command, even a "clean" directory will display all the same files as the commit pointed to by HEAD.
git ls-files --stage
(I assume that this displays the files in the index because stage is synonymous with index)
Why would git store "un-added" files in the index? Aren't these files available by looking at HEAD? This seems redundant.
The distinction between HEAD, index, and working tree gets even murkier when reading certain man pages. For example, this is from man git-restore.
By default, if --staged is given, the contents are restored from HEAD, otherwise from the index
- I would think that if b.txtis edited but not added to the index (i.e.git statusshows red letters), then the version ofb.txtin theindexis the same as inHEAD. However,git restore --staged -- b.txtdoes nothing whereasgit restore -- b.txtrestores the working tree to the version in theHEADcommit.
- If stageis synonymous withindexthen why would--stagedrefer toHEADin thismanpage?
 
    