惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
宝玉的分享
宝玉的分享
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
V
Visual Studio Blog
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
P
Proofpoint News Feed
L
LangChain Blog
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】
Martin Fowler
Martin Fowler

Jiajun的技术笔记

你好,2026! TiDB 源码阅读(六):TiDB Coprocessor 源码解析 性能优化的核心思想 TiDB 源码阅读(五):索引 TiDB 源码阅读(四):AST、逻辑计划、物理计划 CockroachDB Serverless Architecture podman 无故退出 Cursor Control-L (CTRL-L) Keyboard Shortcuts in Terminal Replace docker with podman Using xmonad with xfce4 A RC script for freebsd frpc 自己动手写一个k8s controller AI 会取代你的(编程)岗位吗? 自建DERP服务器提升Tailscale连接速度(使用Nginx转发) 自动升级Docker容器 再读《程序员修炼之道-从小工到专家》 让浏览器下载文件 再读《软件随想录》/《黑客与画家》/《软技能》 HTTP 压力测试中的 Coordinated Omission 2的补码 编程语言中的 context 是什么? flutter macOS 构建出错 Flatpak 使用小记 Golang CAS 操作是怎么实现的 PostgreSQL 当MQ来使用 Clash 结合 工作VPN 的网络设计 使用 PostgreSQL 搭建 JuiceFS PostgreSQL 配置优化和日志分析 有GitHub Copilot?那就可以搭建你的ChatGPT4服务 窗口函数的使用(以PG为例)
使用Git Hooks
2016-11-08 · via Jiajun的技术笔记

最近的工作就是,写文档!用markdown来写,然后要遵循一定的格式。 之前都是我写好我负责的一部分,然后打包发送给项目负责人,因为 一开始以为没多少改动,写完就可以了。没想到,要改的还挺多。 今天就把流程自动化了一下。

整体工作流程为:

``编辑文档`` -> ``git push`` -> ``服务端通过hoos执行脚本,自动部署`` -> ``浏览器刷新看效果``

好,现在来看一下GitHooks文档 [#]_ 。我们需要在客户端push之后触发,所以在 服务器端的项目里设置hook。我最开始犯了一个错,就是以为是在客户端git目录一的 .git/hooks 下设置。

.. code:: bash

# cat post-receive
#!/bin/bash

LOG=/var/log/api-generator.log
unset GIT_DIR

echo "lastest generating " `grep '^time' $LOG | tail -n 1`
git -C /srv/api_docs_generator/smartx/input_api_docs pull >> $LOG 2>&1
cd /srv/api_docs_generator/slate
bundle exec middleman build --clean >> $LOG 2>&1 &
echo 'time:' `date` >> $LOG
echo "it's generating html, please visit http://192.168.49.22/docs/dev/"

上面这个hook解决了两个问题:

  • git -C 后面可以指定git目录,一开始我用的是 cd xxx && git pull 完全没效果, 后来改成 git -C 也没效果,原因是,githook调用的时候会设置变量 GIT_DIRunset GIT_DIR 之后直接用 git -C 的方式可以一行搞定。

  • bundle exec middleman build --clean >> $LOG 2>&1 & 让bash进程独立执行,从 而不会阻塞客户端。

我们来看一下客户端输出吧:

.. code:: bash

➜  api-docs git:(master) git push
[email protected]'s password: 
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 365 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: lastest generating  time: Tue Nov 8 16:42:34 CST 2016
remote: it's generating html, please visit http://192.168.49.22/docs/dev/
To [email protected]:/srv/api-docs
236dexx..10xxxx9  master -> master

额,其实没什么技术含量可言。顺便吐槽一句,在开发的时候,chrome的缓存真的很讨人厌。

.. [#] https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks