Mar*_*air 7 git git-checkout githooks
我试图post-commit在每次成功提交后使用以下钩子部署到特定目录:
#!/bin/sh
export GIT_WORK_TREE=/var/www/example/
export GIT_DIR=/home/mark/test/.git/
git checkout -f
Run Code Online (Sandbox Code Playgroud)
但是,提交后我收到以下错误:
$ git commit -m 'An example commit.'
fatal: Unable to create '/var/www/example/.git/index.lock': No such file or directory
[master 0938e48] An example commit.
Run Code Online (Sandbox Code Playgroud)
...好像GIT_WORK_TREE设置被忽略了.为什么设置此环境变量似乎不起作用?我正在使用git版本1.7.4.1.
Mar*_*air 18
这里的问题是,在post-commit钩(也
pre-commit,prepare-commit-msg和commit-msgt)的
GIT_INDEX_FILE环境变量设置为.git/index.(githooks文档中没有记录这一点,但我已经在其他地方发布了环境变量的设置和git hooks中的当前目录.)
GIT_INDEX_FILE环境变量的效果在git手册页的ENVIRONMENT VARIABLES部分中描述为:
GIT_INDEX_FILE
此环境[变量]允许指定备用索引文件.如果未指定,
$GIT_DIR/index则使用默认值.
......出于某种原因,在这种情况下,GIT_INDEX_FILE正在使用相对于GIT_WORK_TREE.
为了使钩子像你期望的那样工作,你只需要取消设置
GIT_INDEX_FILE,所以你的钩子看起来像:
#!/bin/sh
unset GIT_INDEX_FILE
export GIT_WORK_TREE=/var/www/example/
export GIT_DIR=/home/mark/test/.git/
git checkout -f
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4456 次 |
| 最近记录: |