question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run pre-commit while running rebase --continue

See original GitHub issue

Here’s the use case I’ve recently encountered:

  • Your branch has gone stale, so you rebase off of the main branch
  • Merge conflicts arise, so you solve them as they come and run git rebase --continue without creating new commits
  • pre-commit doesn’t run, leaving style violations and lint errors in the new commit history 😿

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
wagnerluis1982commented, Nov 20, 2021

Adding to this thread, I am using a trick to deal with the git limitation:

$ git rebase -x 'git reset --soft HEAD~1 && git commit -C HEAD@{1}' origin/master
Executing: git reset --soft HEAD~1 && git commit -C HEAD@{1}
black....................................................................Passed
flake8...................................................................Passed
[detached HEAD c972492] Add tests for the coolest feature
 Date: Tue Nov 17 22:31:44 2021 +0100
 11 files changed, 147 insertions(+), 15 deletions(-)
 create mode 100644 tests/test_coolest.py
Executing: git reset --soft HEAD~1 && git commit -C HEAD@{1}
black....................................................................Passed
flake8...................................................................Passed
[detached HEAD e3656a8] Complement with more tests
 Date: Sat Nov 20 07:33:50 2021 +0100
 5 files changed, 35 insertions(+), 16 deletions(-)
Successfully rebased and updated refs/heads/coolest-feature.

This is pretty useful when pre-commit rules were updated in master and you want to reapply to all commits in your working branch. Must also work well in rebase --continue.

To make it easier, I added a git alias 😄

$ git config --global alias.pre-commit-rebase "rebase -x 'git reset --soft HEAD~1 && git commit -C HEAD@{1}'"

Source: https://asciinema.org/a/222023

4reactions
asottilecommented, Nov 13, 2020

unfortunately, there’s no git hook that fires on git rebase --continue

but, fortunately, as long as you’ve run git add, you can run pre-commit manually and it will act the same as if you had run a git commit

Read more comments on GitHub >

github_iconTop Results From Across the Web

What git hooks apply to 'git rebase --continue'? - Stack Overflow
This means commit hooks will run (pre-commit, commit-msg, post-commit, etc). There are other situations when rebasing where you can opt to ...
Read more >
pre-commit: How to run hooks during a rebase - Adam Johnson
pre-commit uses Git's hook system to run tools when you commit. Unfortunately, Git doesn't run any hooks when making a commit during a...
Read more >
pre-commit
The first time pre-commit runs on a file it will automatically download, install, and run the hook. Note that running a hook for...
Read more >
How to skip Git commit hooks | bobbyhadz
Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used,...
Read more >
githooks Documentation - Git
The default pre-applypatch hook, when enabled, runs the pre-commit hook, ... This hook is called by git-rebase[1] and can be used to prevent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found