1

I am using the indent (Linux) tool to check the coding conventions on some C code. I want to do it only on the lines that I have modified or added, to avoid flooding the codebase with whitespace/line-break/bracket changes. How can I use the git command-line together with indent to do it?

$ indent -linux myfile.c
dda
  • 6,030
  • 2
  • 25
  • 34
goe1zorbey
  • 73
  • 5
  • I don't think you can; but this is not a Git question. You can get Git to list the lines that you changed, by, e.g., filtering the output of `git diff` or using an external diff. But after that it becomes a question about `indent`, and there I believe the answer is just "you can't do that", or at least, not in a useful way, without writing so much code that you might as well just write your own indent-er. – torek Feb 08 '17 at 08:48
  • You could run `indent -linux myfile.c` first, and then use `git add -p myfile.c` to select lines to be committed (see http://stackoverflow.com/questions/1085162/commit-only-part-of-a-file-in-git). – Mykhailo Feb 08 '17 at 08:53
  • If you only reformatted the altered lines, that's going to lead to some parts of the code using one style, and others using another style which is the worst possible scenario. Better to do it all at once, in its own commit, and get it over with. As for "flooding the codebase", both `git diff` and `git blame` respond to `-w` to ignore whitespace changes. – Schwern Feb 09 '17 at 04:29

0 Answers0