Markus Löning

Software Engineering & Machine Learning

Run pre-commit retrospectively on all changed files in a PR

Posted at Oct 2, 2020 16:10:57 — Last modified at Dec 26, 2023 19:10:10

When I was developing sktime, we sometimes had new contributors who opened a PR but forgot to set up pre-commit.

This is how you can run pre-commit retrospectively on all changed files in the PR from a <feature-branch> into main. First make sure that main is up-to-date, so that your local git state reflects the PR on the remote repository. If you are working with a fork, take a look at GitHub’s guide on how to sync a fork.

Then run the following:

git checkout <feature-branch>
pre-commit run --files $(git diff --name-only HEAD main)