1

我有一个名为uatgit 的分支。

我想获得分支中更新merge的所有文件的克隆。(其背后的基本想法是创建一个构建以上传到 uat 服务器)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即在当前合并中更新所有文件。

4

2 回答 2

2

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

git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD
于 2015-12-03T07:55:32.990 回答
1

一个完整的解决方案。以下是如何使用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
于 2015-12-03T10:55:15.267 回答