4

I would like to use git filter-repo to format all my c++ files in my repos history. To format the files I use clang-format. Doing this with git filter-branch I know that I could do:

git filter-branch --tree-filter 'find . -type f -iname \*\.cpp -o -iname \*\.hpp | xargs clang-format -i' HEAD

but since git suggests to use git filter-repo instead, I would like to do so. However it is unclear to me which callback function to use?

Cheers!

1 Answer 1

3

Alright, I found my answer at the bottom of this cheat sheet. There exists already a lint-history script which does exactly that. with a .clang-format file in the root of the git repo the following worked nicely

lint-history --relevant 'return (filename.endswith(b".cpp") or filename.endswith(b".hpp"))' clang-format -style=file:.clang-format -i
Sign up to request clarification or add additional context in comments.

3 Comments

Could you explain how to make the lint-history script a command? After saving the file, I can run it with python lint-history ..., but how can you get rid of the need for python?
You can do something like stackoverflow.com/questions/27494758/… however running the command with or without python infront should not matter?
Ah, got it. Yes, it works fine with python, but it's for the convenience as well as for learning. I had tried chmod +x earlier, but I see now that it also needs to be in the $PATH. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.