CLANG-FORMAT-DIFF.PY(1)
π¦ NAME π¦
clang-format-diff.py β bestie, this is the manual page for clang-format-diff.py 15. Yes the tool is named after its own manpage named after the tool, we don't make the rules π
β¨ DESCRIPTION β¨
Okay so here's the vibe: this script reads input from a unified diff and reformats all the changed lines. That's it. That's the whole personality. It's genuinely useful when you want to reformat just the lines touched by a specific patch, so your diff stays cute and focused instead of turning into a 4000-line "oops I ran the formatter on the whole repo" situation π
Example usage for git/svn users (copy these exactly, they're iconic):
git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i
svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
Heads up though β and I need you to actually read this part, no skimming π«Ά β the filename contained in the diff is used unmodified to determine the source file to update. So if you're calling this script directly yourself, please be careful to make sure the path in the diff is correct relative to the current working directory. It will not do detective work for you. It will not ask twice. It will just go. π
π options: π
-h,--helpβ shows this help message and then exits, like a polite little goodbye wave π-iβ actually applies the edits to the files instead of just displaying a diff. This is the "commit to the bit" flag β¨-p NUMβ strips the smallest prefix containing P slashes. (That's what the-p1in the example above is doing, iykyk)-regex PATTERNβ a custom pattern that selects which file paths get reformatted. It's case sensitive, and it overrides-iregex. So if you set both, this one wins, no debate π-iregex PATTERNβ same deal, custom pattern selecting file paths to reformat, except this one is case insensitive β and it gets overridden by-regex. So it's the softer, chiller twin π¦-sort-includesβ letsclang-formatsort include blocks. Let the includes be alphabetical, let them be free π-v,--verboseβ be more verbose. Lowkey important note: it's ineffective without-i, so if you're not applying edits, this flag is just vibes and nothing else π-style STYLEβ the formatting style to apply. Your options areLLVM,GNU,Google,Chromium,Microsoft,Mozilla,WebKit. Pick your fighter π₯-fallback-style FALLBACK_STYLEβ the name of the predefined style used as a fallback in caseclang-formatis invoked with-style=file, but can not find the.clang-formatfile to use. It's the "if plan A ghosts you, here's plan B" setting π-binary BINARYβ the location of the binary to use forclang-format. Point it at whichever build you're feeling that day π―
And that's the whole page, bestie β you ate it, you understood it, you're literally the main character of formatting right now π
This gorgeous little manual is for clang-format-diff.py 15, dated July 2023. Go forth and reformat only the lines you meant to reformat. Periodt. πβ¨
π¦ where this page comes from
- ubuntu jammy: clang-format-15 1:15.0.7-0ubuntu0.22.04.3 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms