How to view the index version of a file before committing it?

I just executed git add --interactive , so the index version of some files is different from the working directory versions. Instead of doing git diff --cached I want to actually dump the contents of each file in the index, but I cannot find a command for this. I should think that there will be something like git show INDEX:filename... but "INDEX" is not a valid object name.

I was able to execute git ls --cached , then git show <hash> , but there should be an easier way to see what you are doing.

+7
git
source share
2 answers

Yes, just:

 git show :filename 

If you have multiple versions of the index (for example, in a merge conflict situation), you can view the versions in different index slots with:

 git show :1:filename git show :2:filename git show :3:filename 

In most other cases, only slot 0 is populated, and :0:filename is the identifier for the cached version of the file. :filename is short for :0:filename .

+17
source share

If you want to check the version of the project that you specified in the index, you can use git stash --keep-index (see Testing partial commits "in the git-stash manpage).

+3
source share

All Articles