先选定一个目录作为Git仓库,假定是/home/www/,在/www/目录下输入命令:
[root@localhost www]# git init --bare test.git
Initialized empty Git repository in /home/www/test.git/
此时用户是root创建的,所以git clone的时候,需要带root用户名,例如:git clone ssh://root@127.40.46.51:64/home/www/test.git,而不是git clone ssh://git@121.40.46.51:64/home/www/test.git,确定用户是root而不是git,没有端口的不需要ssh,ssh默认22端口
git clone ssh://root@127.40.46.51:64/home/www/bossgooexpo.git(注意,没有指定端口的不需要ssh,ssh默认22端口,git clone root@127.40.46.51/home/www/test.git)
此时克隆的时候需要密码,你必须添加秘钥,就不需要密码了,只需要把自己的公钥(id_rsa.pub)放到远程服务器的~/.ssh/authorized_keys文件里就行,
后面push和pull就可以不用输入密码了
git想让服务器接到修改更新后自动同步代码到网站目录中,便于测试开发
如下操作是可以实现:
#假定网站目录在/home/www/wwwroot/
cd /home/www/test.git/hooks
vim post-receive #创建一个钩子
#写入下面内容
GIT_WORK_TREE=/home/www/wwwroot/ git checkout master -f
#保存退出
如此,下次提交修改,代码会自动同步到指定目录中
在本地新增一个index.html文件
git add .
git commit -m "新增一个index.html文件"
git push origin master
然后线上会自动同步到/home/www/wwwroot/目录中
如果此文对你有所帮助,请随意打赏鼓励作者^_^
最新评论
总共0条评论