GIT POST-MERGE Hook,获取更新文件



我在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吗,即在当前合并中更新所有文件。

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

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

获取完整的解决方案。以下是如何使用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

最新更新