使用Git来部署线上代码
来源:互联网 发布:数据结构设计怎么写 编辑:程序博客网 时间:2024/05/24 05:26
- 在服务器端的项目目录下执行:
git init
使项目目录成为一个git目录
- 使服务器端的该Git目录接受push(关键)
git config receive.denyCurrentBranch ignore
- 使服务器端每次被push时执行版本设置
# cd .git/hooks //进入.git目录中的钩子目录# ls //查看钩子目录下文件,这些都是各个钩子对应的文件示例 ( 注意,只是示例!)applypatch-msg.sample post-commit.sample post-update.sample pre-commit.sample pre-rebase.samplecommit-msg.sample post-receive.sample pre-applypatch.sample prepare-commit-msg.sample update.sample
从文件名可以看出钩子被执行的时机,钩子也分为客户端的钩子和服务器端的,比如pre-receive
和post-receive
就属于Git服务器端(也就是接收push的一方)的钩子。
编辑post-receive.sample文件:
#!/bin/sh## An example hook script for the "post-receive" event.## The "post-receive" script is run after receive-pack has accepted a pack# and the repository has been updated. It is passed arguments in through# stdin in the form# <oldrev> <newrev> <refname># For example:# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master## see contrib/hooks/ for a sample, or uncomment the next line and# rename the file to "post-receive".#. /usr/share/git-core/contrib/hooks/post-receive-emailunset $(git rev-parse --local-env-vars)cd /home/git/example/usr/bin/git reset --hard HEAD
注意最后要将 post-receive.sample
改名成 post-receive
,否则不会生效的,脚本中对这一点也有说明。
当本地代码push到服务器上来时就会执行此钩子,将工作区的版本设置成最新的版本,从而实现代码的更新。
最后将 post-receive 设置成可执行:
chmod a+x .git/hooks/post-receive
- 在本地把项目克隆下来
git clone git@xxx.xxx.com:\home\git\example
- 在本地修改代码后使用
git push origin master
命令将更新推送到服务器端,更新就自动部署了,这只是针对静态文件的一些设置,如果需要重启nginx服务器之类的根据需求去写钩子脚本文件。
0 0
- 使用Git来部署线上代码
- 使用git拉取线上
- 使用git部署代码到github
- 使用Git和Github来管理代码
- 使用Git来部署一个Web站点笔记
- 使用Git来部署一个Web站点笔记
- git使用情景1:正在写代码,突然线上出现了bug
- 使用git-flow来帮助管理git代码
- 使用git-flow来帮助管理git代码
- GIT 代码自动部署
- Git自动化部署代码
- 使用git代替FTP部署代码到服务器的例子
- 【Webhooks】使用Git的Webhooks进行服务器自动部署代码
- (git)Bitbucket使用WebHook实现自动部署PHP代码
- 简单使用Git和Github来管理自己的代码
- 使用Git和Github来管理自己的代码
- Mac下使用git difftool来做代码比较
- 如何使用Git和GitHub来管理自己的代码
- React-Native的基本控件属性方法 对React-Native的学习,从熟悉基本控件开始。
- git初探(2)
- ArcObjects中的IGeometry转成Json
- 把arguments转换为数组
- Android之Service
- 使用Git来部署线上代码
- 英语学习的一点东西
- Python创建虚拟环境
- 五子棋(人机)-alpha-beta剪枝
- Android之BroadcastReceiver
- npm install出错
- python实现多线程压测post接口服务
- hive和hadoop的dos操作语句
- 堆排序