【问题标题】:How can I checkout a Git repot *to* a remote folder?如何签出 Git 存储库 * 到 * 远程文件夹?
【发布时间】:2015-03-20 08:35:23
【问题描述】:

给定一个裸存储库,我可以在 post-receive 挂钩中使用 git --work-tree=/path/to/folder --git-dir=/path/to/bare.git checkout -f 将头部检出到 folder,而无需在其中包含 .git 文件夹。当folder 位于远程机器上时,我该如何做到这一点?

我知道git clone --depth=1,但我不能使用它,因为远程文件夹可能已经存在。 rsync [--delete] 也不是一个选项,因为我想要每个文件夹的本地文件,但不在 repo 中(例如,所有文件夹都包含不同的 confi.local.ini)。

【问题讨论】:

    标签: git githooks


    【解决方案1】:

    我终于合并了不同的解决方案,现在我的post-receive 中有以下内容:

    function clone_dev() {
        # This function ssh's to a remote machine (or "localhost") and pulls the
        # latest changes from the bare repo without leaving traces of .git.
        # This approach allows to "local" files to not be overwritten.
        DEV_SSH=$1 # ex: "gitusr@localhost"
        DEV_DIR=$2 # ex: "/data/production/development"
        REPO_DIR_SSH=$3 # ex: "ssh://gitusr@localhost/data/bare.git"
        BRANCH=master
    
        echo -e "\e[1;31mDeploying to '${DEV_SSH}${DEV_DIR}' ...\e[0m"
        echo ""
        ssh "${DEV_SSH}" /bin/bash <<EOF
    if [[ ! -d "${DEV_DIR}" ]]; then
        git clone -b $BRANCH --single-branch --depth=1 "${REPO_DIR_SSH}" "${DEV_DIR}"
        cd $DEV_DIR
        git checkout -f $BRANCH
    else
        cd "${DEV_DIR}"
        git init
        git remote add -t $BRANCH origin "${REPO_DIR_SSH}"
        git fetch --depth=1 origin
        git checkout -f -t origin/$BRANCH
    fi
    cd "${DEV_DIR}"
    rm -rf "${DEV_DIR}"/.git
    EOF
        echo ""
    }
    
    ...
    REPO_DIR_SSH=ssh://gitusr@$HOSTNAME/$REPO_DIR
    
    # the locations of the cutting-edge systems
    DEVELOPMENT1_SSH=gitusr@$HOSTNAME
    DEVELOPMENT1_DIR=/data/production/development
    ...
    
    clone_dev "$DEVELOPMENT1_SSH" "$DEVELOPMENT3_DIR" "$REPO_DIR_SSH"
    clone_dev "$DEVELOPMENT2_SSH" "$DEVELOPMENT2_DIR" "$REPO_DIR_SSH"
    

    部分窃取自:https://stackoverflow.com/a/22597919/2923406https://stackoverflow.com/a/11498124/2923406

    【讨论】:

      猜你喜欢
      • 2020-11-27
      • 2015-10-19
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-04
      相关资源
      最近更新 更多