简体   繁体   English

为什么git私有标签和相关的私有代码上传到公共存储库?

[英]Why are git private tags and associated private code uploaded to public repositories?

I maintained a git tree which contained numerous branches, some private and some pushed to a public repository at bitbucket. 我维护了一个git树,其中包含许多分支,有些是私有的,有些是推送到bitbucket上的公共存储库的。 I recently unintentionally discovered that if I tag commits in the private branches, then uploading tags with 我最近无意间发现,如果我在私有分支中标记提交,则使用

git push --tags

leads to all the commits in the private branch and the private tags being uploaded as a dangling tag. 导致将私有分支中的所有提交和私有标签作为悬挂标签上载。 This exposed a whole lot of private code that was never intended to be public, leading to me deleting the whole repository and re-uploading it without the offending tags to try and fix the issue. 这暴露了很多从未公开的私人代码,导致我删除了整个存储库并重新上传它,而没有令人讨厌的标签来尝试解决此问题。

I've created a sample git tree with only 2 public commits and one private commit in a separate private branch showing how pushing tags pushed the private tag and associated private commit here: https://bitbucket.org/ckolivas/testtag/commits/all PU1 and PU2 were tags made on the master branch and PR1 a tag made on the private branch. 我在一个单独的私有分支中创建了一个仅包含2个公共提交和一个私有提交的示例git树,在此处显示了推送标签如何将私有标签和相关的私有提交推送: https : //bitbucket.org/ckolivas/testtag/commits/所有 PU1和PU2都是在主分支上创建的标签,而PR1是在私有分支上创建的标签。

Is this the correct behaviour that wanting to push tags will make it push ALL the tags, even if they're not part of master? 这是否是要推送标签的正确行为,即使它们不是主服务器的一部分,也要使其推送所有标签? It seems counter-intuitive to me. 对我来说似乎违反直觉。

Is this the correct behaviour that wanting to push tags will make it push ALL the tags, even if they're not part of master? 这是否是要推送标签的正确行为,即使它们不是主服务器的一部分,也要使其推送所有标签? It seems counter-intuitive to me. 对我来说似乎违反直觉。

Tags has nothing to do with master or any other branch. 标签与master或任何其他分支无关。 Tags are simply reference to a commit and indeed you "load" them to the remote using the ``push --tags` 标签只是对提交的引用,实际上,您可以使用“ push --tags”将其“加载”到远程

"Private" branches are local branches which are not published to remote repository. “私人”分支是本地分支,不会发布到远程存储库。
"Public" branches are branches in the remote repository. “公共”分支是远程存储库中的分支。


Best practice 最佳实践

If you use tags prefer the annotated tag git tag -a over the "regular tag" git tag . 如果使用标签,则首选带注释的标签git tag -a而不是“常规标签” git tag It will create annotated tag with the same info as commit so you can view it later on. 它将创建带有与提交相同信息的带注释的标记,以便您以后可以查看它。


From the git push documentation: git push文档中:

git push --follow-tags

You can also use the git push --follow-tags to push all your tags 您还可以使用git push --follow-tags推送所有标签

--follow-tags -关注标签

Push all the refs that would be pushed without this option, and also push annotated tags in refs/tags that are missing from the remote but are pointing at commit-ish that are reachable from the refs being pushed. 推送所有不带此选项将被推送的ref,并推送带注释的标签到远程丢失的ref / tag中,但指向被推送的ref可以到达的commit-ish。

This can also be specified with configuration variable push.followTags . 也可以使用配置变量push.followTags进行指定。
For more information, see push.followTags in git-config . 有关更多信息,请参见git-config中的 push.followTags

--tags -标签

All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line. 除了在命令行上明确列出的refspecs之外,还会推送refs/tags下的所有refs。

This is the correct bahaviour, since you are uploading all tags. 这是正确的行为,因为您正在上传all标签。 If you wish to only upload tags associated with some "public" branches, then list those tags explicitly, like 如果您只想上传与某些“公共”分支关联的标签,则可以明确列出这些标签,例如

git push some_remote some_public_tag

Fom the documentation for git push : 提供git push的文档

--tags

All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line. 除了在命令行上明确列出的refspecs之外,还会推送refs/tags下的所有refs。

So, yes, git push --tags pushes all tags. 所以,是的, git push --tags推送所有标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在私有 git 服务器上使用公共 git 存储库 - Using public git repositories on private git server 具有敏感数据的私有和公共Git存储库 - Private and public Git repositories with sensitive data 如何将私人组织的 Git 存储库与公共 GitHub 存储库同步? - How to synchronize private organization's Git repositories with public GitHub? 单个 Git 存储库中的公共和私有代码 - Public and private code in a single Git repository 使用Apache和mod_macro设置私有的多个公共/私有Git存储库 - Setting up private multiple public/private Git repositories with Apache and mod_macro Yarn 不安装 git 私有存储库 - Yarn not install git private repositories 私有存储库的Git身份验证失败 - Git Authentication Failing for Private Repositories 如何使用私有git存储库中的应用程序代码构建docker映像? - How to build docker images with app code from private git repositories? git 工作流:文件夹内容不同但不会合并的公共和私有存储库 - git workflow: public and private repositories where folder contents diverge but won't be merged 如何使用 git 或在 Vim 中使用 Fugitive 在终端中列出我的所有 Github 存储库,公共和私有存储库? - How to list all my Github repositories, public and private in the terminal with git or in Vim with Fugitive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM