【发布时间】:2017-10-26 11:49:36
【问题描述】:
我正在尝试使用 GIT 中的 Pre-push 挂钩创建一个检查点,我正在检查本地分支和远程分支名称是否相同。
并且仅当本地和远程分支相同时才允许推送。我在预推示例挂钩文件中尝试了类似的操作,但它不起作用。请提出建议。
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_ref" != "$remote_ref" ]
then
echo " Please check Remote and local branch names";
exit 1
else
exit 0
fi
done
更新:我的本地分支是“git push command”中的Mybranch,远程分支是refs/for/Mybranch
因此,即使我的分支名称相同,它也会给我错误,我如何才能从远程中仅提取分支名称,不包括 /refs/for?
Git 推送命令:
git push origin Mybranch:refs/for/Mybranch
【问题讨论】:
-
删除
else exit 0。确保钩子的名称恰好是pre-push并且它是可执行的。 -
嗨,当我的分支名称相同时,这也给了我错误,因为我正在将我的更改推送到 Gerrit/review 分支因此我的 Local = Mybranch 和 Remote= refs/for/Mybranch 我如何削减参考/for/ 来自 remote_ref 变量?
-
推送分支时,
local_ref为refs/heads/Mybranch,remote_ref为refs/for/Mybranch。 -
是的,但我只想将 Mybranch 和 Mybranch 分别作为本地和远程进行比较,所以我正在尝试:同时读取 local_ref local_sha remote_ref remote_sha do remote_ref >> remote.txt remote_ref1 = cat remote.txt | cut -d'/' -f3 rm remote.txt if [ "$local_ref" != "$remote_ref1" ] then echo " Please check Remote and local branch names"\n exit 1 else exit 0 fi done'