Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run git hook before push and amend the last commit?

I want to amend the latest commit with the output of some automated script before the push, but for the push to include the latest change. Using husky I've written this:

"husky": {
    "hooks": {
        "pre-push": "yarn my-script"
    }
}

where

"my-script": "custom-script && git add changed.file && git commit --amend --no-edit"

The problem with it is that push still works with the commits before the latest amended change - which makes sense to some extent.

Is it possible to do with git-hooks?

like image 996
Vladyslav Zavalykhatko Avatar asked Dec 06 '25 18:12

Vladyslav Zavalykhatko


1 Answers

pre-push hook can be used to prevent a push but it cannot change commits being pushed. You need one of the pre-commit hooks.

like image 69
phd Avatar answered Dec 09 '25 19:12

phd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!