从Github更新克隆的回购

如果有任何部分令人困惑,我很抱歉; 现在是11:21 PM,自从1PM以来,我一直在努力实现这一目标。

我使用git clone git@github.com:username/repo.git /var/www将一个私人Github存储git clone git@github.com:username/repo.git /var/www到我的工作目录。 这完美的作品! 没有麻烦。

我已经在Github上设置了一个webhook来通知我的服务器任何新的推送事件。 这个webhook应该从Github仓库中取出并更新任何修改过的文件。 它没有这样做。

每次我调用webhook并运行我将要显示的命令时,它都会响应,表明它与“最新版本”是“最新的”,但它表示最新版本是它最初的版本克隆。

我已经完成了我可以找到的每个解决方案,而且似乎没有任何适用于我的特定问题的解决方案。 我的PHP webhook目前运行如下(因为它是我放弃的地方):

git reset --hard HEAD
git pull
git status
git submodule sync
git submodule update
git submodule status

这应该是一种为我一次更新多台服务器的方法..一种连接一切的方法。 目前,这整个事情唯一连接的是我的额头上的键盘。

任何帮助是极大的赞赏。


这是一个SSH错误。 对于任何有类似问题的人,请确保Git正在寻找你的id_rsa在正确的位置:)


(如果我正确诊断出你面临的问题,我不完全确定,所以这是一个黑暗中的刺。)

你使用git通过ssh登录到github( git@github.com:username/repo.git )。
如果您是通过从不同用户shell(例如webserver用户)运行的脚本来执行此操作,那么该脚本可能无法访问您的SSH-Agent ,因此无法访问您的私钥并且无法登录SSH。
您需要告诉git如何使用环境变量 SSH_AUTH_SOCKSSH_AGENT_PID找到已加载并解锁Github私钥的SSH代理。

注意:如果你想“一次更新多个服务器”,这意味着你想要一个服务器端的git回购镜像,请考虑使用git mirror来代替。 这不会浪费工作目录结账的空间,并自动镜像所有远程参考,包括(例如)github合并请求; 尽管它不会看到/关心子模块(您将不得不为主要的repo手动创建镜像)。
如果你想修改这些文件并将其推回去,那么当然你可能需要workdir。


示例Cron脚本通过ssh传输远程更新本地git镜像; 使用钥匙串工具进行ssh代理管理。
(显然你必须适应这个概念以适合你的php脚本。)

$ crontab -e
# m  h   dom mon dow   command
0    23   *   *   *    cd /my/mirrors/ && sh update-mirrors.sh

和脚本内容:

$ cat /my/mirrors/update-mirrors.sh
#!/bin/sh

# Git mirrors are created with `git clone --mirror ...`
# to "convert" existing local repo into mirror, use
# $ git clone --mirror --no-hardlinks <local-git-path> <new-mirror.git>
# then update the origin remote to the upstream repo and run
# `git remote update`

# Crontab script needs ssh agent
# This sources a file generated by `keychain' with the following info:
#
#SSH_AUTH_SOCK=/tmp/ssh-TLf5KUaqLQgk/agent.15740; export SSH_AUTH_SOCK;
#SSH_AGENT_PID=15731; export SSH_AGENT_PID;
#
# You may do this some other way
#
. $HOME/.keychain/`/bin/hostname`-sh

d=`pwd`
cd $d

# Now update mirrors (our convention: end dirnames with '.git')
DIRS=`ls -dR *.git`

for f in $DIRS; do
        echo "$f"
        cd "$d"
        if [ -f "$f/HEAD" ]; then
                 cd "$f"
                 echo "* updating bare/mirror repo $f ..."
                 git remote update --prune
        elif [ -d "$f/.git" ]; then
                cd "$f"
                echo "updating clone $f ..."
                git remote update
                #git pull
        fi
done
链接地址: http://www.djcxy.com/p/37821.html

上一篇: Update cloned repo from Github

下一篇: Undo a git merge after origin pull