发出自动执行git钩子中的post-commit来同步本地和远程目录 [英] Issue in automatic executing post-commit in git hook to sync local and remote directory
问题描述
我有一个只有git仓库的服务器,我想用hook来同步内容和工作,这样我就可以将我的本地目录同步到服务器的工作目录。
谷歌在这里和那里搜索;这是我迄今为止所做的。
ssh setup
来自 https://stackoverflow.com/a/13542644/260127 和关于在amazon cloud ec2上设置git的虚拟问题
$ b local:
ssh-keygen - t rsa -b 1024
并将其命名为 id_rsa_aws
。然后创建 id_rsa_asw
和 id_rsa_aws.pub
文件。 访问服务器: ssh -i amazon-generated-key.pem ubuntu@example.com
将生成的 服务器: local: 服务器: 在本地目录中进行一些更改。 创建一个 当我从本地计算机推送到服务器时,没有问题。 但是,post-commit不会自动调用。我可以登录到服务器,然后执行 什么可能是错误的? 钩子错了,钩子脚本应该是 这是 I have a server that has bare git repository, and I'd like to use hook to sync the contents with a working so that I can sync my local directory to the working directory in the server. Googling here and there; this is what I have done so far. From https://stackoverflow.com/a/13542644/260127 and Dummy questions about setting up git on amazon cloud ec2 local: access to the server: append the generated server: local: server: Make some changes in a local directory. Make a
When I push from my local machine to server, there is no issue. However, the post-commit is not invoked automatically. I can login to the server, and execute the What might be wrong? The hook was wrong, the hook script should have been This is the content of the
这篇关于发出自动执行git钩子中的post-commit来同步本地和远程目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! id_rsa_aws.pub
键添加到〜/ .ssh / authorized_keys $ c
创建一个git仓库
mkdir -p 〜/ GIT中/ dumb.git; cd〜/ git / dumb.git; git init --bare
git clone ubuntu@example.com:git / dumb.git
从服务器的工作目录中推送
git clone〜/ git / dumb.git
从本地工作目录推送。
git add 。 git commit -m...;
git push --set-upstream origin master
git push
创建挂钩
〜/ git / dumb.git / hooks / post-commit
,然后用 chmod运行它a + x提交后
。
#!/ bin / bash
unset GIT_INDEX_FILE
git --work-tree = / home / ubuntu / dumb --git-dir = / home / ubuntu / git / dumb.git checkout -f
ISSUE
哑GT; git push
计数对象:3,完成。
使用多达8个线程的增量压缩。
压缩对象:100%(2/2),完成。
写入对象:100%(3/3),278字节| 0字节/秒,完成。
总计3(delta 0),重用0(delta 0)
到ubuntu@prosseek.com:git / dumb.git
5964789..b29c160 master - > master
post-commit
并且同步工作目录。
post-receive
不是 post-commit
。来自
的提示
post-receive
钩子的内容。
#!/ bin / bash
unset GIT_INDEX_FILE
while readre oldrev newrev ref
do
if [[$ ref =〜 。* / master $]];
然后
echoMaster ref received。将主分支部署到生产...
git --work-tree = / home / ubuntu / dumb --git-dir = / home / ubuntu / git / dumb.git checkout -f master
echoRef $ ref successfully successfully。Do not nothing:只有主分支可以部署在这台服务器上。
fi
完成
ssh setup
ssh-keygen -t rsa -b 1024
and name it id_rsa_aws
. Then id_rsa_asw
and id_rsa_aws.pub
file is created. ssh -i amazon-generated-key.pem ubuntu@example.com
id_rsa_aws.pub
key into ~/.ssh/authorized_keys
.creating a git bare repository
mkdir -p ~/git/dumb.git; cd ~/git/dumb.git; git init --bare
git clone ubuntu@example.com:git/dumb.git
Push from server's working directory
git clone ~/git/dumb.git
Push from local working directory.
git add .; git commit -m "...";
git push --set-upstream origin master
git push
Create a hook
~/git/dumb.git/hooks/post-commit
, then make it runnable with chmod a+x post-commit
. #!/bin/bash
unset GIT_INDEX_FILE
git --work-tree=/home/ubuntu/dumb --git-dir=/home/ubuntu/git/dumb.git checkout -f
ISSUE
dumb> git push
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 278 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ubuntu@prosseek.com:git/dumb.git
5964789..b29c160 master -> master
post-commit
and the working directory is synced. post-receive
not post-commit
. Hints from
https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-taskspost-receive
hook.#!/bin/bash
unset GIT_INDEX_FILE
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production..."
git --work-tree=/home/ubuntu/dumb --git-dir=/home/ubuntu/git/dumb.git checkout -f master
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done