与使用Github的人共享git repo的一个分支的好方法是什么? [英] What is good way to share one branch of git repo with someone using Github?

查看:204
本文介绍了与使用Github的人共享git repo的一个分支的好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 master进行开发.我们将 stable 主题分支合并到母版中.对于我们的客户,我们从主人那里分支.我们需要让一些外部协作者(通常是前端开发人员)在客户分支上进行协作.但是,他们绝对不能访问(读或写)其他分支或母版(理想情况下,甚至在客户分支分离之前,都无法访问项目的历史记录).

We use master for developement. We merge stable topic braches to master. For our clients we branch from master. We need to let some external collaborators (typically frontend devs) collaborate on client's branch. But they MUST NOT have any access (read or write) to other branches or master (ideally not even to project's history before the client's branch diverged).

我的想法是,我们可以创建一个新的存储库,其中版本0"将是一个新的存储库,其中客户的分支分支不同,并使用pull请求将更改存储到规范存储库中.有什么办法吗?我的意思是从其他仓库的一些具体修订版开始创建空仓库.

My idea was that we could create a new repo, where "revision 0" would be the one, where the client's branch diverged and use pull requests to pull changes to the canonical repo. Is there any way to do that? I mean to create empty repo starting with some concrete revision of other repo.

我认为应该是可能的-因为内容将是相同的-哈希也将是相同的.但是,简单地复制和粘贴修订将不起作用,或者容易出错,因为新创建的请求必须与规范存储库中的请求完全相同,以具有相同的哈希值.

I think it should be possible - because the content will be the same - so will the hash. But simple copy&paste of a revision would not work, or will be error-prone as the newly created request would need to be EXACTLY the same as the one in the canonical repo to have same hash.

请注意,我们使用Github作为git托管,并且我们无意创建自己的git托管.

Please note we use Github as our git hosting and we have no intentions to create our own git hosting.

推荐答案

如果您要使客户端和主客户端彼此隐藏,则每个客户端将需要一个专用存储库.您将拥有一个内部仓库,其中包含您自己的开发,以及一个针对每个客户的孤立分支.当您要创建新的客户分支时,您将

You are going to need one private repository per client, if you want to hide the clients from each other and your master. You'll have one internal repository that contains your own development, and an orphaned branch for each of your clients. When you want to create a new client branch, you'll do

git checkout --orphan client_xx
git commit

然后您将拥有一个孤立的分支,其中包含当时您的master分支的确切内容.要创建客户端存储库,您需要使用一个临时分支来做一些小技巧

Then you'll have an orphaned branch containing the exact contents of your master branch at that time. To create a client repository you need to do a little trick with a temporary branch

mkdir -p /path/to/client_xx
cd /path/to/client_xx
git init
git fetch /path/to/internal client_xx:tmp
git checkout tmp
git branch master
git checkout master
git branch -d tmp

现在,客户端存储库的master分支将包含与内部存储库的客户端分支完全相同的sha1.您可以让客户端派生客户端存储库并向您发出拉取请求.您可以通过拉到客户端分支将客户端存储库集成到内部存储库中.您无法将客户分支正确合并到主分支中(反之亦然),但是您可以使用cherry-pick进行集成.

Now the master branch of the client repository will contain the exact same sha1 as the client branch of your internal repository. You can have the client fork the client repository and make pull requests to you. You can integrate the client repository into your internal repository by pulling to the client branch. You cannot properly merge the client branch into master branch (or vice versa) as the client branch was orphaned, but you can do the integration using cherry-pick.

这篇关于与使用Github的人共享git repo的一个分支的好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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