使用两个 git 存储库(内部和外部)向客户端交付代码的工作流程
Workflow for delivering code to a client using two git repositories (internal and external)
我有一种情况,客户端将收到源代码,在使用 Git 的版本控制下。客户希望跟踪、区分和控制每周冲刺的进度到他们的回购中。最终,客户人员也会对该回购做出承诺。
我的团队(我们称之为内部团队)也在使用 Git 和 git-flow 工作流程。所以 internal 回购的每个 release 应该转化为 client 上的 commit 回购。我们不希望内部仓库中的每个提交都显示在客户端仓库中。
所以我目前的 thinking/solution 是有一个脚本使用 rsync 将工作目录从内部复制到客户端(在本地文件系统上),然后提交到客户端 repo。这可以作为 post-receive 挂钩放置在内部服务器或类似的东西上。
这个解决方案对我来说似乎太笨拙了,也许有更好的方法来实现我的需要。还有什么想法?
编辑以包含已接受的解决方案:
正如 Scott Weldon 在接受的回复中指出的那样,git-merge
允许在良好的工作流程中执行此操作。但是,要使其工作,还需要其他标志。一是让git有效合并两个故事,二是给出解决冲突的适当策略。
因此,假设我从 内部 存储库合并的引用是 release/x.x.x.
,流程是
git fetch internal
git merge --allow-unrelated-histories -s recursive -Xtheirs --squash internal/release/x.x.x
git commit
git push origin master
实现此目的的一种方法是使用 Git 添加和合并不相交历史记录的能力。
将内部存储库作为远程存储库添加到您的外部存储库:
git remote add internal ssh://user@host/path.git
每当您在内部仓库中发布时,请在外部仓库中执行以下操作:
git fetch internal
git merge --squash internal/master
git commit
git push origin master
这将在外部存储库中创建一个提交,其中包含自上次合并以来 internal/master
的所有更改。
来自 git merge
的手册页:
--squash
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD
, or record $GIT_DIR/MERGE_HEAD
(to cause the next git commit
command to create a merge commit). This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in the case of an octopus).
因此,如果没有 --squash
标志,来自 internal
的历史记录将包含在外部存储库中。
如果您使用的版本是 Git >= 2.9,那么您还需要在 git merge
命令中添加 --allow-unrelated-histories
标志,因为 Git默认情况下将拒绝合并不相关的历史记录。参见 Git refusing to merge unrelated histories。
我有一种情况,客户端将收到源代码,在使用 Git 的版本控制下。客户希望跟踪、区分和控制每周冲刺的进度到他们的回购中。最终,客户人员也会对该回购做出承诺。
我的团队(我们称之为内部团队)也在使用 Git 和 git-flow 工作流程。所以 internal 回购的每个 release 应该转化为 client 上的 commit 回购。我们不希望内部仓库中的每个提交都显示在客户端仓库中。
所以我目前的 thinking/solution 是有一个脚本使用 rsync 将工作目录从内部复制到客户端(在本地文件系统上),然后提交到客户端 repo。这可以作为 post-receive 挂钩放置在内部服务器或类似的东西上。
这个解决方案对我来说似乎太笨拙了,也许有更好的方法来实现我的需要。还有什么想法?
编辑以包含已接受的解决方案:
正如 Scott Weldon 在接受的回复中指出的那样,git-merge
允许在良好的工作流程中执行此操作。但是,要使其工作,还需要其他标志。一是让git有效合并两个故事,二是给出解决冲突的适当策略。
因此,假设我从 内部 存储库合并的引用是 release/x.x.x.
,流程是
git fetch internal
git merge --allow-unrelated-histories -s recursive -Xtheirs --squash internal/release/x.x.x
git commit
git push origin master
实现此目的的一种方法是使用 Git 添加和合并不相交历史记录的能力。
将内部存储库作为远程存储库添加到您的外部存储库:
git remote add internal ssh://user@host/path.git
每当您在内部仓库中发布时,请在外部仓库中执行以下操作:
git fetch internal
git merge --squash internal/master
git commit
git push origin master
这将在外部存储库中创建一个提交,其中包含自上次合并以来 internal/master
的所有更改。
来自 git merge
的手册页:
--squash
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the
HEAD
, or record$GIT_DIR/MERGE_HEAD
(to cause the nextgit commit
command to create a merge commit). This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in the case of an octopus).
因此,如果没有 --squash
标志,来自 internal
的历史记录将包含在外部存储库中。
如果您使用的版本是 Git >= 2.9,那么您还需要在 git merge
命令中添加 --allow-unrelated-histories
标志,因为 Git默认情况下将拒绝合并不相关的历史记录。参见 Git refusing to merge unrelated histories。