【发布时间】:2019-12-02 12:40:26
【问题描述】:
我正在尝试使用新的 git hook pre-merge-commit 创建一个特定的脚本,但它没有参数。
是否有任何解决方法,以便我可以获取正在合并的分支的名称?
示例: 在分支 myBranch 上,我调用“git merge testingBranch”,我想在我的脚本中获取那个“testingBranch”。
原因:我需要阻止将项目中的一个特定分支合并到任何其他分支。 所以它会是这样的:
if [[ "$originOfMergeBranchName" == "testingBranch" ]]
then
echo "You can't merge this branch to any other"
exit 2
fi
我在思考如何获得 originOfMergeBranchName 时遇到了麻烦
提前致谢:D
【问题讨论】:
-
我可以运行
git merge <hash>,其中<hash>是testingBranch的尖端或testingBranch的尖端后面的提交,您将无法可靠地检测到这一点(尤其是如果该提交也是其他一些分支的提示)。所以这可能是首先要解决的错误问题。但是,如果您想尝试找到git merge命令的参数,请考虑获取进程树并检查它们的参数。