一家专门做软件的网站,如何在网站上木马,wordpress模板 购买,网站建设在哪里进行Git是什么自不必说。Git和gitlab安装和实践在后边的俩篇中会写。本篇仅重点写Git自动部署。Git同样有Hooks,可以用于各种需求。可以控制提交commit名称#xff0c;可以控制代码规范#xff0c;也当然包含以下要介绍的自动部署#xff0c;也不仅包含这些。Git自动部署简单的思… Git是什么自不必说。Git和gitlab安装和实践在后边的俩篇中会写。本篇仅重点写Git自动部署。Git同样有Hooks,可以用于各种需求。可以控制提交commit名称可以控制代码规范也当然包含以下要介绍的自动部署也不仅包含这些。Git自动部署简单的思想是这样在服务端创建空版本库在客户端创建真实版本库关联远程版本库在服务端部署代码在服务端版本库中修改新增钩子程序服务端创建空版本库 [yuargcv-com ~]$ cd [yuargcv-com ~]$ mkdir repo[yuargcv-com ~]$ cd repo/[yuargcv-com repo]$ git init --bare test.gitInitialized empty Git repository in /home/yu/repo/test.git/[yuargcv-com repo]$2. 在客户端创建真实版本库关联远程版本库[yuargcv-com ~]$ cd /tmp/
[yuargcv-com tmp]$ mkdir client
[yuargcv-com tmp]$ cd client/
[yuargcv-com client]$ git init
Initialized empty Git repository in /tmp/client/.git/
[yuargcv-com client]$ git remote add origin yulocalhost:repo/test.git
[yuargcv-com client]$ touch README.md
[yuargcv-com client]$ git add .
[yuargcv-com client]$ git commit -m init
[master (root-commit) 00da9a9] init1 file changed, 0 insertions(), 0 deletions(-)create mode 100644 README.md
[yuargcv-com client]$ git push origin --all
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To yulocalhost:repo/test.git* [new branch] master - master
[yuargcv-com client]$3.在服务端部署代码[yuargcv-com ~]$ cd /tmp/
[yuargcv-com tmp]$ mkdir deploy
[yuargcv-com tmp]$ cd deploy/
[yuargcv-com deploy]$ git clone ~/repo/test.git .
Cloning into ....
done.4.在服务端版本库中修改新增钩子程序[yuargcv-com repo]$ pwd
/home/yu/repo
[yuargcv-com repo]$ cd test.git/
[yuargcv-com test.git]$ cd hooks/
[yuargcv-com hooks]$ vi post-receive
[yuargcv-com hooks]$ cat post-receive
#!/bin/sh
unset GIT_DIR
NowPathpwd
echo now path is :$NowPath
DeployPath/tmp/deploy
echo deploy path is :$DeployPath
cd $DeployPath
echo cd deploy path
#git add . -A git stash # remove local changes
git pull origin master # pull data from master
# the follow line is also ok:
# git add . git fetch origin git reset --hard origin/master
echo deploy done
cd $NowPath
echo fine
# --- Finished
exit 0
[yuargcv-com hooks]$ chmod x post-receive
[yuargcv-com hooks]$5.测试[yuargcv-com client]$ touch newfile
[yuargcv-com client]$ git add .
[yuargcv-com client]$ git commit -m add new file
[master 68efdcf] add new file1 file changed, 0 insertions(), 0 deletions(-)create mode 100644 newfile
[yuargcv-com client]$ git push origin
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 384 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: now path is :/home/yu/repo/test.git
remote: deploy path is :/tmp/deploy
remote: cd deploy path
remote: From /home/yu/repo/test
remote: 6627165..5ac80ec master - origin/master
remote: Updating 6627165..5ac80ec
remote: Fast-forward
remote: newfile | 0
remote: 1 file changed, 0 insertions(), 0 deletions(-)
remote: create mode 100644 newfile
remote: deploy done
remote: fine
To yulocalhost:repo/test.gitb3a32f2..5ac80ec master - master
[yuargcv-com client]$ 转载于:https://blog.51cto.com/rhino/1843183