mirror of
https://github.com/ZJDoc/GitGuide.git
synced 2026-07-29 15:20:25 +08:00
docs(git): add advanced and error
This commit is contained in:
32
docs/git/advanced/工作目录和裸仓库分离.md
Normal file
32
docs/git/advanced/工作目录和裸仓库分离.md
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
# 工作目录和裸仓库分离
|
||||
|
||||
裸仓库指`.git`文件夹,工作目录指除`.git`文件夹外的其他文件
|
||||
|
||||
使用场景之一如下:
|
||||
|
||||
1. 本地将修改好的代码上传到远程裸仓库
|
||||
2. 裸仓库获取到代码后,通过钩子生成工作目录,放置在其他路径下
|
||||
3. 服务器再对工作目录进行操作,比如`nginx`对静态文件进行托管
|
||||
|
||||
在`.git/hooks`文件夹下新建`post-receive`文件
|
||||
|
||||
$ vim post-receive
|
||||
|
||||
添加如下内容
|
||||
|
||||
#!/bin/sh
|
||||
|
||||
git --work-tree=工作目录 --git-dir=裸仓库 checkout -f
|
||||
|
||||
授予执行权限
|
||||
|
||||
$ sudo chmod +x post-receive
|
||||
|
||||
## 相关阅读
|
||||
|
||||
* [GIT_DIR和GIT_WORK_TREE的妙用,工作区和仓储可隔离](http://www.yinqisen.cn/blog-718.html)
|
||||
|
||||
* [通过git自动部署WEB服务上的PHP代码,提交即生效](http://www.yinqisen.cn/blog-675.html)
|
||||
|
||||
* [8.3 自定义 Git - Git 钩子](https://git-scm.com/book/zh/v2/%E8%87%AA%E5%AE%9A%E4%B9%89-Git-Git-%E9%92%A9%E5%AD%90)
|
||||
Reference in New Issue
Block a user