Git挂钩可以在子模块更改时更新超级项目? [英] Git hook to update superproject on submodule change?

查看:75
本文介绍了Git挂钩可以在子模块更改时更新超级项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个git存储库:ABC. C是一个包含子模块AB的超级项目,跟踪每个子模块各自的主分支.

I have three git repositories: A, B, and C. C is a superproject including submodules A and B, tracking each submodule's respective master branch.

更改AB的主分支时,我必须在C中执行以下操作:

When the master branch of A or B is changed, I must do the following in C:

git submodule update --remote
git add A
git add B
git commit -m "Update submodule A or B"
git push

此时,将执行从C进行的自动构建和部署.

At this point an automated build and deploy from C is executed.

我正在寻找简化此过程的方法.理想情况下,对AB的master分支的任何提交都会触发钩子来更新,提交和推送到C.有什么想法可以实现这一目标吗?

I'm looking for ways to streamline this process. Ideally, any commit to the master branch of A or B would trigger a hook to update, commit, and push to C. Any ideas how to achieve this?

如果有我应该了解的特定于供应商的功能,则我将Azure DevOps用于git托管,并将Azure Pipelines用于构建和部署过程.

In case there's a vendor-specific feature I should be aware of, I'm using Azure DevOps for the git hosting and Azure Pipelines for the build and deploy process.

推荐答案

您可以使用git post-commit

You can use a git post-commit hook, when you do a commit in the submodules the hook will be executed and will do the commands.

  1. 转到每个子模块存储库.
  2. 使用以下内容创建文件 .git/hooks/post-commit :

#!/bin/sh

branch="$(git rev-parse --abbrev-ref HEAD)"

if [ "$branch" = "master" ]; then
  cd {super repo location}
  git submodule update --remote
  git add A
  git add B
  git commit -m "Update submodule A or B"
  git push
fi

  • 使其可执行(在 Windows 上不是必需的):

  • Make it executable (not required on Windows):

    $ chmod +x .git/hooks/pre-commit
    

  • 这篇关于Git挂钩可以在子模块更改时更新超级项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆