一、先git clone 代码php
二、配置nginx,域名绑定到代码目录html
三、在代码目录建立 webhook.php (随意命名)nginx
<?php $pwd = getcwd(); $command = 'cd ' . $pwd . ' && git pull 2>&1'; // 2>&1 是输出错误,有利于调试 $output = shell_exec($command); file_put_contents('./webhook.log', $output);// 输出内容保存到日志,须要注意日志文件要有足够的权限 print $output; ?>
四、配置码云webhook,url为 http://yourdomain/webhook.phpgit
五、碰到问题了:git pull 须要输入帐号密码web
解决办法:shell
执行git config --global credential.helper store命令 而后git push origin your-branch // your-branch就是分支的名字 //会让你输入用户名和密码,就会保存起来,下次就不须要了
六、建立密钥服务器
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter] // 这里填写 /home/www/.ssh/id_rsa,由于nginx用户组是www,以后一路回车
$ eval $(ssh-agent -s)
$ ssh-add /home/www/.ssh/id_rsa
以后就复制 /home/www/.ssh/id_rsa_pub里面的内容,添加到码云->设置->SSH公钥里面dom
注意:/home/www/.ssh 目录用户组:用户须要设置为, chown -R www:www /home/www/.sshssh
Git 常见问题解决url
Your local changes to the following files would be overwritten by merge: index1.html Please, commit your changes or stash them before you can merge
在服务器上能够直接执行退回上一个版本,再拉取代码(由于没人会在服务器开发,代码都在码云,不担忧没了)
git reset --hard git pull origin your-branch