我有一个叫做post-checkout的git checkout钩子
$ ll /usr/local/Cellar/git/2.3.5/share/git-core/templates/hooks/post-checkout
-rwxr-xr-x 1 root wheel 375 Aug 13 14:11 /usr/local/Cellar/git/2.3.5/share/git-core/templates/hooks/post-checkout
结帐后的内容为:
#!/usr/bin/env bash
echo "Hello from post-checkout"
# Delete .pyc files and empty directories from root of project
cd ./$(git rev-parse --show-cdup)
# Clean-up
find . -name ".DS_Store" -delete
NUM_PYC_FILES=$( find . -name "*.pyc" | wc -l | tr -d ' ' )
if [ $NUM_PYC_FILES -gt 0 ]; then
find . -name "*.pyc" -delete
printf "\e[00;31mDeleted $NUM_PYC_FILES .pyc files\e[00m\n"
fi
所以当我克隆我的repo时,我将模板的路径传递给模板标志,如下所示:
$ git clone https://[email protected]/sanfx/git-maildiff.git --template=/usr/local/Cellar/git/2.3.5/share/git-core/templates/
但是在我克隆并CD到git-maildiff的克隆目录并尝试 checkout 之后,我什么也没有得到。
$ git clone https://[email protected]/sanfx/git-maildiff.git --template=/usr/local/Cellar/git/2.3.5/share/git-core/templates/
Cloning into 'git-maildiff'...
remote: Counting objects: 239, done.
remote: Compressing objects: 100% (215/215), done.
remote: Total 239 (delta 109), reused 0 (delta 0)
Receiving objects: 100% (239/239), 72.90 KiB | 0 bytes/s, done.
Resolving deltas: 100% (109/109), done.
Checking connectivity... done.
$ git checkout
Your branch is up-to-date with 'origin/master'.
但是如果我运行我的可执行post-checkout分支,我会得到在shell中打印的Hello from post-checkout。
哪里出了问题?
3条答案
按热度按时间vhipe2zx1#
根据文档后结帐脚本接收3个参数。我遇到了类似的问题,我解决了添加一行来读取这些参数(不使用它们并不重要)。该脚本将如下所示:
v7pvogib2#
我需要更新这个文件:
而不是这个:
am46iovg3#
确保您的
post-checkout
文件设置为可执行文件。否则Git会忽略它。