frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Pre-commit hooks are fundamentally broken

https://jyn.dev/pre-commit-hooks-are-fundamentally-broken/
57•todsacerdoti•6h ago

Comments

nrclark•2h ago
This was a really interesting read. I'd highly recommend it for anybody who's setting up (or currently maintains) a pre-commit workflow for their developers.

I want to add one other note: in any large organization, some developers will use tools in ways nobody can predict. This includes Git. Don't try to force any particular workflow, including mandatory or automatically-enabled hooks.

Instead, put what you want in an optional pre-push hook and also put it into an early CI/CD step for your pull request checker. You'll get the same end result but your fussiest developers will be happier.

Mic92•2h ago
I can second that. If there are multiple commits: https://github.com/tummychow/git-absorb is handy to add formatting changes into the right commit after commits already happened.
eru•55m ago
> This includes Git. Don't try to force any particular workflow, including mandatory or automatically-enabled hooks.

And with git, you can even make anything that happens on the dev machines mandatory.

Anything you want to be mandatory needs to go into your CI. Pre-commit and pre-push hooks are just there to lower CI churn, not to guarantee anything.

(With the exception of people accidentally pushing secrets. The CI is too late for that, and a pre-push hook is a good idea.)

normie3000•49m ago
> with git, you can even make anything that happens on the dev machines mandatory

s/can/can't?

tkzed49•1h ago
Thank you. I don't need to "fix" a commit before it ends up on a remote branch. Sometimes I expect a commit to pass checks and sometimes I don't. Frankly, don't even run pre-push hooks. Just run the checks in CI when I push. You'd better be doing that anyway before I'm allowed to push to a production branch, so stop breaking my git workflows and save me the time of running duplicate checks locally.

Also, if most developers are using one editor, configure that editor to run format and auto-fix lint errors. That probably cleans up the majority of unexpected CI failures.

eru•53m ago
Pre-commit and pre-push hooks are something developers can voluntarily add (or enable) to shorten the latency until they get feedback: instead of the CI rejecting their PR, they can (optionally!) get a local message about it.

Otherwise, I agree, your project can not rely on any checks running on the dev machine with git.

hbogert•24m ago
I don't want roundtrips to my CI which easily takes a minute and pushes me to look at yet another window. Pre-commit hooks save me so much time.
Simplita•1h ago
I’ve seen similar issues once hooks start doing more than fast checks. The moment they become stateful or depend on external context, they stop being guardrails and start being a source of friction. In practice, keeping them boring and deterministic seems to matter more than catching everything early.
badgersnake•1h ago
Yep, all that and they’re also annoying. Version control tools are not supposed to argue - do what you’re told. If I messed up, the branch build will tell me.
thomashabets2•57m ago
Is that the difference between forced pre commits vs opt in? I don't want to commit something that doesn't build. If nothing else it makes future bisects annoying.

But if I intend to squash and merge, then who cares about intermediate state.

normie3000•45m ago
> I don't want to commit something that doesn't build.

This is a really interesting perspective. Personally I commit code that will fail the build multiple times per day. I only care that something builds at the point it gets merged to master.

hbogert•22m ago
so basically, not adhering to atomic commits. That's fine if it's a deliberate choice, but some people like me think commits should stand on their own.

(i'm assuming your are not squashing when merging, else it's pretty much the same workflow)

nine_k•1h ago
A bit less enraged: pre-commit hooks should be pure functions. They must not mutate the files being committed. At best, they should generate a report. At worst, they could reject a commit (e.g. if it contains a private key file included by mistake).
normie3000•47m ago
> e.g. if it contains a private key file included by mistake

Thanks - this is the first example of a pre-commit hook that I can see value in.

Ferret7446•32m ago
In my experience pre-commit hooks are most often used to generate a starting commit message.

To put it more bluntly, pre-commit hooks are pre-commit hooks, exactly what it says on the tin. Not linting hooks or checking hooks or content filters. Depending on what exactly you want to do, they may or may not be the best tool for the job.

To put it even more bluntly, if you are trying to enforce proper formatting, pre-commit hooks are absolutely the wrong tool for the job, as hooks are trivially bypassable, and not shared when cloning a repo, by design.

thomashabets2•1h ago
I feel like I found better git commands for this, that don't have these problems. It's not perfect, sure, but works for me.

The pre commit script (https://github.com/ThomasHabets/rustradio/blob/main/extra/pr...) triggers my executor which sets up the pre commit environment like so: https://github.com/ThomasHabets/rustradio/blob/main/tickbox/...

I run this on every commit. Sure, I have probably gone overboard, but it has prevented problems, and I may be too picky about not having a broken HEAD. But if you want to contribute, you don't have to run any pre commit. It'll run on every PR too.

I don't send myself PRs, so this works for me.

Of course I always welcome suggestions and critique on how to improve my workflow.

And least nothing is stateful (well, it caches build artefacts), and aside from "cargo deny" no external deps.

000ooo000•52m ago
Only a minor suggestion: git worktrees is a semi-recent addition that may be nicer than your git archive setup
000ooo000•56m ago
Your hook can't observe a simple env var, if you are stepping off the happy path of your workflow? E.g. `GIT_HOOK_BYEBYE` = early return in hook script. Article seems a little dramatic. If you write a pre-commit hook that is a pain in your own arse, how does that make them fundamentally broken?
lemonlime227•51m ago
To bring up jujutsu, `jj fix` (https://docs.jj-vcs.dev/latest/cli-reference/#jj-fix) is a more refined way of ensuring formatting in commits. It runs a formatting command with the diff in stdin and uses the results printed to stdout. It can simplify merges and rebases history to ensure all your commits remain formatted (so if you enable a new formatting option, it can remove the need for a special format/style fix commit in your mutable set). Hard to go back to pre-commit hooks after using jj fix (also hard to use git after using jj ;) ).
dbt00•45m ago
Came here to mention jj fix. It is a fundamentally more elegant way of doing things.
conradludgate•40m ago
The downside currently (although I've been assured this will be fixed one day) is that it doesn't support running static analysis over each commit you want to fix.

My git rebase workflow often involves running `git rebase -x "cargo clippy -- --deny=warnings"`. This needs a full checkout to work and not just a single file input

conradludgate•36m ago
I've worked in several projects where running the tests locally automatically install pre-commit hooks and I've wanted to commit warcrimes because of it.

Don't do that, just dont.

wolfi1•30m ago
why do people rebase so often? shouldn't it be excluded from the usual workflows as you are losing commit history as well?
hbogert•28m ago
why would you lose commit history? You are just picking up a set of commits and reapplying them. Of course you can use rebase for more things, but rebase does not equal losing commit history.
mcny•20m ago
I write really poopy commit messages. Think "WIP" type nonsense. I branch off of the trunk, even my branch name is poopy like

feature/{first initial} {last initial} DONOTMERGE {yyyy-MM-dd-hh-mm-ss}

Yes, the branch name literally says do not merge.

I commit anything and everything. Build fails? I still commit. If there is a stopping point and I feel like I might want to come back to this point, I commit.

I am violently against any pre commit hook that runs on all branches. What I do on my machine on my personal branch is none of your business.

I create new branches early and often. I take upstream changes as they land on the trunk.

Anyway, this long winded tale was to explain why I rebase. My commits aren't worth anything more than stopping points.

At the end, I create a nice branch name and there is usually only one commit before code review.

rkomorn•11m ago
Isn't your tale more about squashing than rebasing?
nacozarina•20m ago
really; keep reading about all the problems ppl have “every time I rebase” and I wonder what tomfoolery they’re really up to
UqWBcuFx6NV4r•18m ago
I think that only the most absolutely puritan git workflows wouldn’t allow a local rebase.
marginalia_nu•8m ago
The sum of the re-written changes still amount to the same after a rebase. When would you need access to the pre-rebase history, and to what end?
a_t48•15m ago
Running on the working tree is mostly okay - just `exit 1` if changes were made and allow the user to stage+commit new changes. It isn't perfect but it doesn't require checking out a new tree.

Show HN: Ez FFmpeg – Video editing in plain English

http://npmjs.com/package/ezff
52•josharsh•1h ago•15 comments

How uv got so fast

https://nesbitt.io/2025/12/26/how-uv-got-so-fast.html
889•zdw•17h ago•294 comments

AI Police Reports: Year in Review

https://www.eff.org/deeplinks/2025/12/ai-police-reports-year-review
118•hn_acker•3d ago•63 comments

Mruby: Ruby for Embedded Systems

https://github.com/mruby/mruby
21•nateb2022•5d ago•10 comments

Langjam-Gamejam Devlog: Making a language, compiler, VM and 5 games in 52 hours

https://github.com/Syn-Nine/gar-lang/blob/main/DEVLOG.md
40•suioir•5d ago•2 comments

Exe.dev

https://exe.dev/
210•achairapart•10h ago•100 comments

Experts explore new mushroom which causes fairytale-like hallucinations

https://nhmu.utah.edu/articles/experts-explore-new-mushroom-which-causes-fairytale-hallucinations
391•astronads•17h ago•199 comments

The best things and stuff of 2025

https://blog.fogus.me/2025/12/23/the-best-things-and-stuff-of-2025.html
253•adityaathalye•3d ago•26 comments

Publishing your work increases your luck

https://github.com/readme/guides/publishing-your-work
120•magoghm•9h ago•40 comments

More Dynamic Cronjobs

https://george.mand.is/2025/09/more-dynamic-cronjobs/
36•0928374082•4h ago•6 comments

QNX Self-Hosted Developer Desktop

https://devblog.qnx.com/qnx-self-hosted-developer-desktop-initial-release/
149•transpute•8h ago•79 comments

Pre-commit hooks are fundamentally broken

https://jyn.dev/pre-commit-hooks-are-fundamentally-broken/
57•todsacerdoti•6h ago•30 comments

Researchers develop a camera that can focus on different distances at once

https://engineering.cmu.edu/news-events/news/2025/12/19-perfect-shot.html
49•gnabgib•3d ago•13 comments

One million (small web) screenshots

https://nry.me/posts/2025-10-09/small-web-screenshots/
94•squidhunter•4d ago•8 comments

Always bet on text (2014)

https://graydon2.dreamwidth.org/193447.html
213•jesseduffield•11h ago•110 comments

How Lewis Carroll computed determinants (2023)

https://www.johndcook.com/blog/2023/07/10/lewis-carroll-determinants/
181•tzury•15h ago•45 comments

SIMD City: Auto-Vectorisation

https://xania.org/202512/20-simd-city
40•brewmarche•6d ago•5 comments

Show HN: Witr – Explain why a process is running on your Linux system

https://github.com/pranshuparmar/witr
319•pranshuparmar•18h ago•49 comments

Package managers keep using Git as a database, it never works out

https://nesbitt.io/2025/12/24/package-managers-keep-using-git-as-a-database.html
631•birdculture•21h ago•361 comments

Toys with the highest play-time and lowest clean-up-time

https://joannabregan.substack.com/p/toys-with-the-highest-play-time-and
383•surprisetalk•13h ago•224 comments

T-Ruby is Ruby with syntax for types

https://type-ruby.github.io/
123•thunderbong•13h ago•95 comments

The Proton, the 'Most Complicated Thing You Could Possibly Imagine'

https://www.quantamagazine.org/inside-the-proton-the-most-complicated-thing-imaginable-20221019/
40•tzury•7h ago•7 comments

LearnixOS

https://www.learnix-os.com
233•gtirloni•21h ago•91 comments

Parasites plagued Roman soldiers at Hadrian's Wall

https://arstechnica.com/science/2025/12/study-roman-soldiers-battled-parasites-at-hadrians-wall/
63•sipofwater•1w ago•40 comments

Moravec's Paradox and the Robot Olympics

https://www.physicalintelligence.company/blog/olympics
56•beklein•3d ago•6 comments

Show HN: Xcc700: Self-hosting mini C compiler for ESP32 (Xtensa) in 700 lines

https://github.com/valdanylchuk/xcc700
125•isitcontent•19h ago•20 comments

Ask HN: What did you read in 2025?

231•kwar13•21h ago•322 comments

Drawing with zero-width characters

https://zw.swerdlow.dev
106•benswerd•15h ago•30 comments

My insulin pump controller uses the Linux kernel. It also violates the GPL

https://old.reddit.com/r/linux/comments/1puojsr/the_device_that_controls_my_insulin_pump_uses_the/
419•davisr•15h ago•185 comments

MongoBleed

https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py
75•gpi•15h ago•10 comments