小编fab*_*1An的帖子

git post-receive hook无法跳回原来的cwd

当推送到我们的共享裸存储库(通过ssh)时,后提交无法正常工作.
这是很常见的,因为我在很多线程发现这里并能正常工作在同一台服务器,它驱动我疯了另外两个仓库.

#!/bin/sh
GIT_WORK_TREE=/ab/cd/staging git checkout -f
Run Code Online (Sandbox Code Playgroud)

存储库本身与钩子要检出的目录位于同一目录中

/ab/cd/barerepo
Run Code Online (Sandbox Code Playgroud)

推送时,它不会将文件签出到预期路径,但会显示以下错误消息:

Writing objects: 100% (3/3), 299 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
fatal: Could not jump back into original cwd
error: hooks/post-receive exited with error code 128
Run Code Online (Sandbox Code Playgroud)

我找不到任何关于这意味着什么的信息.(只要我知道,谷歌只会提交对git本身贡献的提交).所以我读了,猜到并试过......

  • 另外在post-receive hook中设置GIT_DIR
  • 使用--git-dir =/ab/cd/barerepo重新初始化裸仓库 - working-dir =/ab/cd/staging
  • 在barerepo/config中手动设置工作目录
  • 设置裸仓库并提交
  • 通过克隆设置裸仓库

现在配置看起来像这样

[core]
     repositoryformatversion = 0
     filemode = true
     bare = true
Run Code Online (Sandbox Code Playgroud)

但我也有这个(不费力)

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
    sharedrepository = 1
    worktree = /ab/cd/staging
    logallrefupdates …
Run Code Online (Sandbox Code Playgroud)

git git-post-receive

8
推荐指数
3
解决办法
2965
查看次数

标签 统计

git ×1

git-post-receive ×1