Possible to read file from git cache?

382 Views Asked by At

I can see list of files using below command

git ls-files --cache

Wondering if it's possible to read the content of the listed file?

2

There are 2 best solutions below

2
phd On BEST ANSWER

Use git cat-file or git show. For example

for f in `git ls-files --cache`; do
    echo -- "----- File (cat): $f -----"
    git cat-file -p HEAD:$f
    echo -- "----- File (show): $f -----"
    git show HEAD:$f
    echo -- "----- End of File: $f -----"
done
0
Rene On

You could use checkout-index. This command copies a file from the git cache (index) into the worktree.

Normally it overrides the working copy, but with the parameter --temp you could create a copy of your file.

git checkout-index --temp -- myfile.ext