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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With