我使用以下接收后 Hook :
GIT_TOP=`git rev-parse --show-toplevel`
while read oldrev newrev refname
do
echo "=== $oldrev"
echo "=== $newrev"
echo "=== $refname"
echo "=== 01. checkout -- $GIT_TOP/*"
git checkout -- "$GIT_TOP/*"
echo "=== 02. merging $refname"
git merge $refname
echo "=== 03. checkout -- $GIT_TOP/*"
git checkout -- "$GIT_TOP/*"
done
想法很清楚:我希望当前分支与推送的分支 merge 。
然后我执行:
git status
它告诉我本地树与分支不同!比我执行的更多
git checkout -- *
在 git dir 的顶部 - 现在这个命令做我想做的事:git status
现在显示没有差异了。
为什么这个命令git checkout -- "$GIT_TOP/*"
没有 Hook 工作,只能通过直接调用工作?如何在钩子(Hook)中运行此命令?
附言
我发现 git rev-parse --show-toplevel
从钩子(Hook)内调用返回 <myrepo>/.git
路径,但从 shell 来看它的值只是 <myrepo>
.也许这有助于解决问题。
最佳答案
好的,现在可以使用了。多思考少抄袭。
export GIT_WORK_TREE=`pwd`
export GIT_DIR=`pwd`/.git
保罗
关于git - 在 git post-receive hook 中 merge ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11375924/