Hi,
I would like to use git clang-format in a pre-commit hook to style the hunks of code I’m about to commit. So far this works great using git clang-format --staged, but it seems like this styles the hunks in the woking copy. On the one hand this is great since I will see the changes in my editor, but I still need to git add the new changes to the commit. There is no problem if I added the entire file, but if I just want to commit some of the changed lines, I didn’t find an easy way to do that. I either have to add each hunk again manually or I can add the entire file using the hook (which I don’t want, since I’ve just added the hunks I want to commit before).
From the description of the --staged option, I thought it would do exactly what I wanted, but this doesn’t seem to be the case. Am I missing something? I’m currently on version 17.0.6, installed via brew.
Some context for my question:
I’m working with quite a large number of developers on a large codebase of varying styles. A subgroup of the developers would like to introduce a uniform style of code we touched, but leave the rest as-is, not to mess with the history of who did what.
This might be related to Git-clang-format --staged formats the worktree instead of the index