Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show complete files as they would exist in the git index

Tags:

git

I'm writing a pre-commit hook, and would like to do a check on the entire contents of each file that's about to be committed (specifically a lint check on the files). I want to lint check the file as it's going to be commited, not as it exists in my working tree (which may differ).

The pre-commit hook example that comes with git shows you how to get the diff (so you can examine for spaces and such), but I need to get the entire file as it's going to be committed.

like image 856
Bryan Alves Avatar asked Aug 27 '09 18:08

Bryan Alves


1 Answers

Try this:

git --work-tree=/path/to/checkout-area checkout-index path/to/file-to-checkout

The --work-tree option tells git to use a different area as the work tree, so that you don't overwrite the file in your true work-tree. You might also want to add the -f option to tell it to overwrite if necessary, but if your script properly cleans up after itself it shouldn't be necessary. See the man page for checkout-index for more information.

like image 185
Cascabel Avatar answered Sep 21 '22 01:09

Cascabel