To intercept the pre-commit, which modifies the staged files, I need to figure out what needs to be done after the hook has been started.
The prefix hook applies pretty nice prints to files that need to be committed. The hook performs the following tasks:
- replace tabs with spaces
- remove trailing spaces at the end of lines
- delete double blank lines *)
- if not, add an empty line at the end of the file *)
Actions marked with *) are those that cause the problem described below.
After this has been done, the hook adds the modified file to the index using git add $filename
. Thus, the whole file will be delivered, and I can no longer make small portions (i.e. Hunks) of the modified file.
Of course, I could git add --no-verify
and bypass the hook, but this option is not available when using git gui
. Also, I want to apply pretty-printed information in staged lines of a file, so hook traversal is not my goal.
Is there any way to find out what needs to be added to the index after pretty printing has been applied so that I can create the right content after the hook has been launched, and not to set up the whole file?
Change 1:
While the answer provided by David Brigada seems promising, it doesn't work: git stash --keep-index
exits the post changes integrity (which is the good part), but (at least on msysgit), it puts all the changes in stash (not only uninstalled). This leads to merge conflicts when attachments appear in the WC, because staged lines can be changed.
Edit 2:
Also, David's updated answer does not lead to success, since git refuses to combine the cache into a dirty toilet.
Edit 3:
A response from larsks indicates the use of .gitattributes
. At first glance this seems correct, but I find it rather confusing that the verified version was run through a filter, and the WC is different from the verified version. At least that was my experience and is reinforced by the following remark in the Git Book :
If you copy these changes and check the file again, you will see that the keyword is correctly replaced
I need to delete the file and then check it again to see the changes that were applied by the filter. Never! Any clues?