Unix
Git - 帶有 git pull 的 post-receive 鉤子“找不到有效的 git 目錄”
這很奇怪,但是在設置 git 儲存庫並使用以下命令創建接收後掛鉤時:
echo "--initializing hook--" cd ~/websites/testing echo "--prepare update--" git pull echo "--update completed--"
鉤子確實執行了,但它永遠無法正確執行 git pull :
6bfa32c..71c3d2a master -> master --initializing hook-- --prepare update-- fatal: Not a git repository: '.' Failed to find a valid git directory. --update completed--
所以我現在問自己,如何讓鉤子用 post-receive 更新複製?
在這種情況下,執行程序的使用者是相同的,並且它的所有內容都在使用者文件夾中,所以我真的不明白……因為如果我手動進入
cd ~/websites/testing git pull
它工作沒有任何問題……
對此的任何幫助將不勝感激
非常感謝
當鉤子執行時,
GIT_DIR
並且(如果工作樹被明確定義)GIT_WORK_TREE
被設置。這意味著您的 pull 不會與您更改到的目錄中的第二個儲存庫一起執行。試試
git --git-dir ~/websites/testing/.git --work-tree ~/websites/testing pull
;或取消設置 git 的 repo-local 環境:unset $(git rev-parse --local-env-vars)
有關這些環境變數的更多資訊man 1 git。
我經歷過的一件事是使用
post-update
鉤子“–git-dir”效果很好,但 git 仍然抱怨缺少工作樹(儘管使用了“–work-tree”)簡而言之,這不起作用:
git --git-dir /path/to/websites/testing/.git --work-tree /path/to/websites/testing pull
而這有效:
`cd /path/to/websites/testing
git –git-dir /path/to/websites/testing/.git pull`