简体   繁体   English

是否可以在push之前运行git hook并修改最后一次提交?

[英]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. 它的问题是在最新修订的更改之前,push仍然可以与提交一起使用-在某种程度上是合理的。

Is it possible to do with git-hooks? 可以用git-hooks做吗?

pre-push hook can be used to prevent a push but it cannot change commits being pushed. pre-push钩子可用于阻止推送,但不能更改被推送的提交。 You need one of the pre-commit hooks . 您需要一个预提交的钩子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM