Question

git diff --staged allows you to view changes between HEAD and the staged changes.

How do I view the full file as it would exist in HEAD if I were to commit the staged changes? How do I view a specific subset of lines from it?

Was it helpful?

Solution

You can view the staged version of a file using:

git cat-file -p :./FILENAME

The leading : causes git to read from the index. The ./ gets it to look in the current directory, this part may be omitted if you specify a path relative to the top of the repository rather than to your current directory.

You can view a specific subset of lines by piping the output from that to another command to do the desired limiting as for any other file.

OTHER TIPS

$ git ls-files --cached --stage
100644 f009acdec84ee338ec99c92920d603a67241608f 0       README

Guest@HOME-PC ~/doubt (master)
$ git cat-file -p f009acdec84ee338ec99c92920d603a67241608f

One
Teo
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top