Is the Git staging area just an index?

后端 未结 5 1967
小鲜肉
小鲜肉 2021-02-07 00:01

The book Pro Git says that the staging area is just a list, or index, that says which files will be committed when a git commit is done, and now the name inde

5条回答
  •  深忆病人
    2021-02-07 00:55

    So how can the "staging area" keep track of what the first edit was if it is just an index -- a list?

    An index is a list of names and pointers to content. In books, it's page numbers. In the Git index, it's object ID's in the repository's object database.

    That's what the Git index is, a pathname-indexed list of content pointers.

    git add for some pathname is basically

    sha=`git hash-object -w path/to/it`
    git update-index --cacheinfo 100644,$sha,path/to/it 
    

    except git add checks for executable files and uses 100755 for those, and does recursive adds and checks your .gitignore and whatever else seems like it's usually most convenient. It's a convenience command for adding content to the object db and updating the index.

提交回复
热议问题