bash脚本里面执行命令的Git [英] execute git command inside bash script
问题描述
我写 Gitosis的
推后挂机中央存储库
I am writing gitosis
post-push hook for central repository
这是直接从中央存储库更新的测试环境。
which pulls updates from central repository to testing enviroment
纳米/var/git/repositories/holding.git/hooks/post-update
#!/bin/bash
cd /var/vh/holding;
git reset --hard;
git checkout testing;
git pull;
在这里我把我的客户端上后,得到(开发VM)
here what I get after push on my client (development VM)
# blah ...
Counting objects: 57, done.
Compressing objects: 100% (24/24), done.
Writing objects: 100% (30/30), 3.42 KiB, done.
Total 30 (delta 18), reused 0 (delta 0)
fatal: Not a git repository: '.'
fatal: Not a git repository: '.'
fatal: Not a git repository: '.'
fatal: Not a git repository: '.'
To git@cheby.ru:holding.git
233b5a2..0f46cd8 testing -> testing
显然,我试图告诉混帐,它应该做的拉动,失败了。
Obviously, my attempt to tell git, where it should do pull, failed.
什么是在bash脚本指定的工作副本运行git命令正确的方式?
What is correct way to run git command for a specified working copy in bash script?
推荐答案
正如前面提到的<一个href=\"http://stackoverflow.com/questions/3542854/calling-git-pull-from-a-git-post-update-hook\">here或<一个href=\"http://serverfault.com/questions/107608/git-post-receive-hook-with-git-pull-failed-to-find-a-valid-git-directory\">there,你可以precede与所有的Git命令:
As mentioned here or there, you could precede all your git commands with:
env -i
,以确保有没有副作用,例如, GIT_DIR
环境变量这本来是previously设置。结果
( ENV -i
或者干脆:取消设置GIT_DIR
)
in order to make sure there is no side effect with, for instance, a GIT_DIR
environment variable which could have been previously set.
(env -i
or simply: unset GIT_DIR
)
这篇关于bash脚本里面执行命令的Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!