在 git Push 上需要带注释的标签并拒绝轻量级标签
是否可以在 git 存储库上设置不允许将轻量级标签推送到其中的策略?
Is it possible to set up a policy on a git repo that disallows lightweight tags from being pushed to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Git hook 页面提到:
该引用依次引用
update.sample
Chris Johnsen 在评论中提到。The Git hook page mentions:
That references in turn the
update.sample
Chris Johnsen mentions in the comments.从 git push 的角度来看,更新钩子是在接收(远程)存储库上调用的。有时,您无权在远程存储库上安装挂钩;据我所知,GitHub 就是这种情况(它很高兴允许推送轻量级标签)。
为了防止从本地存储库推送轻量级标签,您可以将其添加到
.git/hooks/pre-push
中的读取循环主体中,如从pre-push 复制的那样。示例
:但是,我认为最好的解决方案是回避整个问题。
带注释的标签可以与可访问这些标签的任何引用一起自动推送。配置变量
push.followTags
启用此行为,因此您可以在默认情况下执行正确的操作,而几乎不需要显式推送标签:The update hook is invoked on the receiving (remote) repository from the perspective of
git push
. Sometimes, you do not have access to install hooks on remote repositories; as far as I know, this is the case for GitHub (which happily allows pushing lightweight tags).To prevent lightweight tags from being pushed from the local repository, you could add this to the body of the reading loop in
.git/hooks/pre-push
, as copied frompre-push.sample
:However, the best solution in my opinion is to sidestep the whole problem.
Annotated tags can be pushed automatically together with any refs from which these tags are reachable. Configuration variable
push.followTags
enables this behavior, so you can do the right thing by default and hardly ever have to push tags explicitly: