9

I have staged parts of a file in git like so

git add --patch ./file

I would like to output the contents of the staged file to stdout.

Note that the staged file and the file in the working directory are different since I only staged parts of the file.

gustavotkg
  • 4,099
  • 1
  • 19
  • 29
Jean Paul Galea
  • 1,321
  • 4
  • 18
  • 26

1 Answers1

10

If you want to just output the complete file in its staged version, you can use the syntax suggested by grawity in answer to a recent question:

git show :file

... or if you want to see the changes between HEAD and the index for that file (typically the changes you've just staged) you can use:

git diff --cached -- file
Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • 2
    I'm not having luck with `git show :file` if the file has not been previously committed. I had to fall back to `git ls-files -s ` and then `git cat-file -p `. – Christopher King Sep 14 '16 at 20:38