简体   繁体   English

是否可以通过 git hook 触发另一个提交和推送?

[英]Is it possible to trigger another commit and push by git hook?

I work with software which uses git repository to generate (or update) some file on a disk after a successful commit.我使用的软件在成功提交后使用 git 存储库生成(或更新)磁盘上的一些文件。 I'd like to automatically add this generated (updated) file to the git repository.我想自动将这个生成的(更新的)文件添加到 git 存储库中。 It can be contained in the same or the next commit and needs to be also pushed to the remote.它可以包含在同一次或下一次提交中,也需要推送到远程。

I was trying to use git hooks: * pre-commit can't be used because before committing the file which I want to add is not updated * pre-push: updated file can be added and committed to the git, but I'm unable to have it pushed automatically (only first of the two commits is pushed).我正在尝试使用 git 钩子: * 无法使用预提交,因为在提交之前我想添加的文件未更新 * 预推:可以添加更新的文件并将其提交给 git,但我是无法自动推送(仅推送两个提交中的第一个)。 I'm using a script like:我正在使用如下脚本:

pre-push: 'cp../updatedfile.预推:'cp../updatedfile. ; ; git add updatedfile; git 添加更新文件; git commit - m "msg"' git commit -m "msg"'

The ideal solution would be to use something which is triggered after the successfull push of the first commit and then create a second commit (containing updated file) and push them.理想的解决方案是使用在第一次提交成功推送后触发的东西,然后创建第二个提交(包含更新的文件)并推送它们。 Do you know how to resolve it?你知道如何解决吗?

The ideal solution would be to use something which is triggered after the successful push理想的解决方案是使用成功推送后触发的东西

That is a server-side hook , which is not what you want, since the server would not have access to the generated updated side to add and push again.那是一个server-side hook ,这不是你想要的,因为服务器将无法访问生成的更新端来添加和再次推送。

It then depends on where you push.然后,这取决于推动的位置。
On GitHub or GitLab, you would have the notion of webhook (GitLab webhook here ) (also in BitBucket Cloud )在 GitHub 或 GitLab 上,您会有webhook的概念( 此处为 GitLab webhook )(也在BitBucket Cloud中)

The advantage is that you setup a listener for a push event: if that listener is on the client side, where those generated (updated) files are, said listener can, on a push, trigger a second commit/push (if any local updates are detected).优点是您为推送事件设置了一个侦听器:如果该侦听器在客户端,那些生成的(更新的)文件所在的位置,那么侦听器可以在推送时触发第二次提交/推送(如果有任何本地更新被检测到)。

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

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