【问题标题】:GIT POST-MERGE Hook, Get updated filesGIT POST-MERGE Hook,获取更新文件
【发布时间】:2016-03-07 17:05:42
【问题描述】:

我在 git 上有一个名为 uat 的分支。

我想在uat 分支中获取在merge 中更新的所有文件的克隆。
(其背后的基本想法是创建一个构建以上传到 uat 服务器)。

我试过这样做。

#!/bin/bash
branch=$(git symbolic-ref HEAD | sed -e "s/^refs\/heads\///");
if [ "uat" == "$branch" ]; then
    // to do
    // 1. get all updated files
    // 2. create a clone of these files
fi

有人可以帮助我setp 1,即在当前合并中更新所有文件。

【问题讨论】:

    标签: git deployment githooks autodeploy


    【解决方案1】:

    如果合并刚刚发生(在合并后挂钩中应该是这种情况),您可以使用ORIG_HEAD

    git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD
    

    【讨论】:

    • 正是我想要的。谢谢!!
    【解决方案2】:

    完整的解决方案。以下是使用 git post-merge hook 创建构建的方法。

    #!/bin/bash
    
    # get current branch    
    branch=$(git symbolic-ref HEAD | sed -e "s/^refs\/heads\///");
    
    # check if branch name is `uat` (or whatever you prefer)
    if [ "uat" == "$branch" ]; then
    
        # create a folder outside the git repo
        # you can skip this step, if you want a static location
        mkdir -p $(pwd)/../uat/$(basename $(git root));
    
        # getting updated files, and
        # copy (and overwrite forcefully) in exact directory structure as in git repo
        yes | cp --parents -rf $(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD) $(pwd)/../uat/$(basename $(git root))/;
    fi
    

    【讨论】:

    • 很好的反馈,除了我的回答。 +1
    • @VonC.. 你的回答是这个逻辑的核心。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 2016-01-30
    • 2011-06-20
    • 2011-05-08
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    相关资源
    最近更新 更多