我想在 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
目录,因为它应该是。那为什么自动执行不行呢?