Skip to content

Support for pre-rebase Hook #2582

Closed
@BrutalSimplicity

Description

@BrutalSimplicity

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:

https://gist.github.com/uasi/9384329

Activity

asottile

asottile commented on Nov 4, 2022

@asottile
Member

here's some PRs you can draw inspiration from -- #2036 #1800

BrutalSimplicity

BrutalSimplicity commented on Nov 4, 2022

@BrutalSimplicity
Author

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

BrutalSimplicity commented on Nov 4, 2022

@BrutalSimplicity
Author

@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

asottile commented on Nov 4, 2022

@asottile
Member

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

asottile commented on Nov 4, 2022

@asottile
Member

(that is, unless you manually call git commit with no arguments before continuing)

BrutalSimplicity

BrutalSimplicity commented on Nov 4, 2022

@BrutalSimplicity
Author

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

adamchainz commented on Nov 7, 2022

@adamchainz
Contributor

I just blogged about a solution to run hooks during rebase:

$ git rebase -x 'pre-commit run --from-ref HEAD~ --to-ref HEAD' main
deleted a comment from on Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Support for `pre-rebase` Hook · Issue #2582 · pre-commit/pre-commit