How to force all files in git repo to enter the staged state, with no actual changes?

Viewed 277

I am trying to use git clang-format to format all the files in a repo[1], not just a given commit or diff. My first thought was just mark every file as staged and then run the command. Then any files that aren't changed would result in a no-op, but all the files that do have formatting changes would be fixed, staged, and then committed

However, I cannot find a reliable way to force all files to enter the 'staged' state. Even force touching all the files didn't trigger their inclusion.

I have tried variations of git add -a or git add -a -f and that doesn't work.

[1] Yes I could use clang-format directly but depending on versions of clang-format and git clang-format they produce different outputs.

1 Answers

The problem here is that all files are always staged. They're just not called staged unless the staged copy is different from the committed copy.

Given that you plan to run everything through a formatting command, you could simply deform each file (badly format a line at the top, for instance) to fool the software, but it would be better just to use the formatter directly on the working tree files. To handle the footnote-1 issue, find the right formatting directives to get the right formatting.

Related