【问题标题】:Git post-commit hook on Windows results in ".git/index.lock: No such file or directory"Windows 上的 Git post-commit 钩子导致 \".git/index.lock: No such file or directory\"
【发布时间】:2023-02-21 20:26:25
【问题描述】:

我想在 Windows 上每次提交后将我的工作树复制到不同的位置。我添加了一个包含以下内容的提交后挂钩:

#!/bin/bash

# the work tree, where the checkout/deploy should happen
TARGET="C:\Users\...\copy"

# the location of the .git directory
GIT_DIR="C:\Users\...\repo\.git"

BRANCH="master"

echo "Do something"
git --work-tree="${TARGET}" --git-dir="${GIT_DIR}" checkout -f ${BRANCH}

从命令行执行 git commit 时,会产生以下输出:

warning: in the working copy of 'test.html', LF will be replaced by CRLF the next time Git touches it
Do something
fatal: Unable to create 'C:/Users/.../copy/.git/index.lock': No such file or directory
[master c68d639] asdasd
 2 files changed, 4 insertions(+), 2 deletions(-)

从命令行手动执行脚本工作正常,并按要求复制工作树。

MINGW64 ~/.../repo/.git/hooks (GIT_DIR!)
$ ./post-commit
Do something
Already on 'master'

手动执行此脚本后,最终结果目录中没有 .git 目录,因为它应该是。那么为什么自动执行不起作用呢?

【问题讨论】:

    标签: windows git githooks


    【解决方案1】:

    首先检查,作为in here,您是否需要取消设置GIT_INDEX_FILE

    GIT_INDEX_FILE 是索引文件的路径(仅限非裸存储库)。

    一般来说,在一个钩子中,我尝试使用我不需要的 unset GIT_xxx 变量(或者我明确指定,就像你对 --work-tree--git-dir 所做的那样)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2016-09-03
      • 2023-01-22
      • 2018-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多