Closed
Description
Is there a pre-commit hook that can prevent rebase operations? It looks like git does support a pre-rebase
hook, but I didn't see it in the docs.
I checked here.
Example pre-rebase
hook:
Is there a pre-commit hook that can prevent rebase operations? It looks like git does support a pre-rebase
hook, but I didn't see it in the docs.
I checked here.
Example pre-rebase
hook:
Activity
asottile commentedon Nov 4, 2022
here's some PRs you can draw inspiration from -- #2036 #1800
BrutalSimplicity commentedon Nov 4, 2022
Never mind, I think I'm actually looking for the standard
commit
hook functionality. I want to be able to prevent certain commits from being rewritten, which I think that hook can do. Apologies. 😅I'll still leave this open, since it is functionality that doesn't exist.
BrutalSimplicity commentedon Nov 4, 2022
@asottile I appreciate the quick response. Thank you! Not sure if I'll have time soon to add this, but when I have more time, I'll try to take a look if this is still open.
asottile commentedon Nov 4, 2022
if you're trying to hook into individual "commits" that (for example) an interactive rebase makes unfortunately I don't think there's a way to do that (
git rebase --continue
skips hooks in my experience)asottile commentedon Nov 4, 2022
(that is, unless you manually call
git commit
with no arguments before continuing)BrutalSimplicity commentedon Nov 4, 2022
Ahh, thanks for letting me know that. I guess server-side hooks are the way here. Any ideas on how you can implement a server-side hook that will reject a push if a "protected" commit message is modified?
I don't think there is support in
git
for this concept, but some tools like to use git as a more traditional datastore, and if a certain commit is altered, the tools end up in an odd state.As I was typing this it dawned on me that this could possibly be handled by a tagging strategy.
adamchainz commentedon Nov 7, 2022
I just blogged about a solution to run hooks during rebase:
chore(deps): update dependency pre-commit to v3 (#2)