Inc1982
Inc1982

Reputation: 1975

Where is the git index?

In Git the staging area is also referred to as the index. What seems to be said is that when you make changes in your working directory and add these changes to 'staging' git adds these files to an index file. When opening a projects /.git/index file, I see a file that contains text that displays when I type:

git status

I may get output that looks like this:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   Gemfile
#
no changes added to commit (use "git add" and/or "git commit -a")

But in other places like Git Index Contents they say that by typing:

git ls-files --stage

You can see the contents of the index.. though this is clearly not what is in /.git/index. What file in the .git directory actually houses this index? What I suspect, and I may be wrong.. is that .git/index is storing the change information in the 'modified' line and then when typing git ls-files --stage that it is building up a a list of the files that are staged and their hashes based on the files in the working directory and those that are listed as modified in this index file.. Is this correct?

Upvotes: 4

Views: 2107

Answers (1)

manojlds
manojlds

Reputation: 301097

The index file at .git/index is not a text file and is a binary file that has the necessary information about the index and is the index.

I don't understand what you are trying to say with the git status output. git status outputs even untracked files. Are you saying that index also has knowledge of untracked files in it? Of course not.

Upvotes: 5

Related Questions