如何保持 git repo 的公共和私有版本同步? [英] How to keep public and private versions of a git repo in sync?

查看:26
本文介绍了如何保持 git repo 的公共和私有版本同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在 Github 上发布一个开源 Rails 应用程序(可能是 MIT 许可证).我还想维护项目的私有分支/分支,我们将其用作付费服务的一部分.

在这种情况下组织回购的最佳方式是什么?而且,当我有应该同时进行的更新时,我如何保持项目同步?

解决方案

最简单的解决方案是在您的私有"存储库中拥有私有分支,即简单的分支未推送到公共存储库.

为此,您可能需要在配置中指定要推送到公共存储库的所有分支(而不是使用全局镜像 refspec +refs/*:refs/*),或者小心推送您想要发布的分支并依赖于推送匹配分支(存在于远程端的分支)设置push.default"的 Git 行为;到当前默认值匹配".

如果您不小心推送了您的私有分支,您可以使用git push remote>"在远程存储库中删除它(除非它被配置为禁止这样做).:refs/heads/<private-branch>";(记住这一点:将空值推送到远程分支).您可以使用远程侧的钩子防止意外推送您的私有分支,例如参见更新-偏执 contrib/examples 中的示例钩子.


旁注: git 维护者 Junio C Hamano 仅将指定的一组分支推送到公共 git 存储库:maint"、master"、next"、pu"(建议更新),和 'html', 'man', 'todo';他不发布短命的、经常变化的功能分支.



示例设置:

<前>工作存储库 ----> 私有存储库(裸) ----> 公共存储库------ 私有 -------/------- 受保护的 -----/------- 公共 -----/

工作存储库"是具有您进行提交的工作区的存储库,您可以在其中提取更改并解决冲突;您工作的存储库.假设它包含以下分支:公开"的更改可以发布到全世界,私有"您不想与他人共享或仅与选定的人共享,也许还有一些功能分支,例如票证-234' 或 'add-frobnicator',它们甚至还没有准备好供选定的组查看.这个存储库是非裸的,因为它没有发布.

推送到私有"存储库将具有类似于以下配置的内容.请注意,匹配分支"是指匹配分支".行为在此处明确设置,参见git-pull 联机帮助页:

[远程私有"]url = user@example.com:/srv/private/git/repo.git推 = +:

私人存储库"是仅对选定的人可用的公共裸存储库,例如它只能通过 SSH 获取.它只有准备好的分支,即公共"和私有"分支;这些分支在创建私有"时存在存储库,或者从工作"中明确推送(git push private ")存储库.从工作"推存储库仅推送(传输)匹配的分支,即仅公共"和私有"分支.

私人仓库"具有 post-updatepost-receive 钩子集,将公共"分支推送到公共存储库";(见下文)如果它被推送到它(好吧,它可以无条件推送).

公共存储库"是所有人都可以使用的公共裸存储库,例如它托管在 GitHub、和/或 Gitorious、和/或 repo.or.cz 上,或者它可能是使用 git 通过 git:// 协议提供的-守护进程.它只包含 'public' 分支,它使用 updatepre-receive 要么接受分支列表(这里只接受 'public' 分支),要么拒绝黑名单分支(在本例中推送到/创建私有"分支将被拒绝).当推送到私人"时它会自动更新存储库.

对于您的需要,此设置可能过于复杂;私人"在您的情况下可能不需要存储库.在这种情况下,工作存储库"中的配置不可用.用于直接推送到公共存储库"看起来像这样:

[存储库公共"]url = ssh://example.com/srv/git/repo.git推 = refs/heads/public:refs/heads/public

我希望这个例子会有所帮助;但是请阅读文档,不要盲目使用.

I'm releasing an open-source Rails app on Github (probably MIT license). I also want to maintain a private branch/fork of the project that we will use as part of a pay service.

What is the best way to organize the repo(s) in this scenario? And, how can I keep the projects in sync when I have updates that should go to both?

解决方案

The simplest solution would be to have private branch in your 'private' repository, i.e. branch which is simply not pushed to public repository.

For that you would probably need to either specify all branches you want to push to public repository in config (instead of using globbing mirroring refspec +refs/*:refs/*), or push carefully branches you want to publish and rely on Git behaviour of pushing matching branches (those which are present on remote side) setting "push.default" to current default value "matching".

If you by accident push your private branch, you can delete it in remote repository (unless it is configured to forbid this) using "git push <remote> :refs/heads/<private-branch>" (to remember this: push empty value to remote branch). You can protect against accidental pushing of your private branch using hooks on remote side, see e.g. update-paranoid example hook in contrib/examples.


Sidenote: Junio C Hamano, git maintainer, pushes to public git repositories only specified set of branches: 'maint', 'master', 'next', 'pu' (proposed updates), and 'html', 'man', 'todo'; he does not publish short-lived often changing feature branches.



EXAMPLE SETUP:

    working repository  ---->  private repository (bare)  ---->  public repository  
    ------ private -------/     ------- protected ------------/     ------- public -----/

"Working repository" is the repository with working area that you make commits in, where you pull changes and resolve conflicts; repository where you do your work. Let's say it contains the following branches: 'public' with changes that can be published to the world, 'private' that you want to not share with others or share only with selected subset of people, and perhaps some feature branches like 'ticket-234' or 'add-frobnicator', which are not ready even for selected group to see. This repository is non-bare, as it not published.

It would have something like the following configuration for pushing to 'private' repository. Note that "matching branches" behavior is set explicitely here, see git-pull manpage:

[remote "private"]
        url = user@example.com:/srv/private/git/repo.git
        push = +:

"Private repository" is public bare repository available only to selected people, for example it is available for fetching only via SSH. It has only branches which are ready, i.e. 'public' and 'private' branches; either those branches were present when creating "private" repository, or were pushed explicitely ("git push private <branch>") from "working" repository. Push from "working" repository pushes (transfers) only matching branches, i.e. only 'public' and 'private' branches.

"Private repository" has post-update or post-receive hook set which pushes 'public' branch only to "public repository" (see below) if it was pushed to it (well, it can push unconditionally).

"Public repository" is public bare repository available to everyone, for example it is hosted on GitHub, and/or Gitorious, and/or repo.or.cz, or perhaps it is served via git:// protocol using git-daemon. It contains only 'public' branch, and it uses update or pre-receive either to accept whilelist of branches (here only 'public' branch is accepted), or reject blacklist of branches (in this example pushes to/creating 'private' branch would be rejected). It is updated automatically when pushing to "private" repository.

This setup might be overly complicated for your needs; "private" repository might be not necessary in your case. In such case the configuration in "working repository" for pushing directly to "public repository" would look like this:

[repository "public"]
        url = ssh://example.com/srv/git/repo.git
        push = refs/heads/public:refs/heads/public

I hope this example would help; please however read the documentation and do not use it blindly.

这篇关于如何保持 git repo 的公共和私有版本同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆