4

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?

1

1 Answer 1

5

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.

2
  • 1
    Wow my apologies.. apparently I am using vim-fugitive which when I attempt to open the index file in vim it just write the output of git status to the open buffer... this really confused me.. I now see that your answer that .git/index is a binary actually makes sense.. Thanks.
    – Inc1982
    Commented Mar 12, 2013 at 4:03
  • I ran into that same issue with vim-fugitive. It was really confusing. Thanks for the explanation @Inc1982
    – Ryan Quinn
    Commented Jan 18, 2020 at 19:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.