发布私有git存储库的某些路径

Tho*_*yer 5 git gitlab

我在一个包含以下项目的私有gitlab存储库中与一个约10个开发团队合作:

  1. 服务器
  2. AI
  3. 客户
  4. 接口
  5. 杂项(协议,PR材料等)

除了Misc之外,其中每个都有自己的Maven依赖项和单元测试包含在它们的特定文件夹中.

我们正在使用git-flow,因此所有分支将develop在某个时刻与一个分支合并.


题:

我们目前只销售带有源的客户端和接口,并且希望允许我们的客户只访问这些(子)项目,包括他们的历史,同时能够轻松推送更新并使用gitlab的issues功能.

我的想法:

  1. 如果它是一个公共回购,我会简单地使用git submodules,但这个解决方案似乎与私有存储库完美无缺.(如果有的话 - 已经阅读了很多关于无效路径的问题)
  2. 如果我有超洁净分支机构ClientInterface,我可以添加其他新的remote存储库,只需按下这两个分支它.这个解决方案的问题在于,我们没有经验丰富的开发人员和一个肮脏的推动或从develop分支机构的一次推动基本上会使整个想法变得毫无用处.风险太高了.
  3. 另一个想法我已经在动这2个子项目进行私人回购,创建子模块的私人回购协议.这在某种程度上也感觉非常不方便,因为我们continuous integration会在不同的回购中运行,并且我们自己的问题也会在那里进行跟踪.

由于这是一个非常具体的设置和计划,我会对你的想法感兴趣,以解决这样的情况.谢谢你的时间.

Tho*_*yer 0

如果找到更优雅的解决方案或者我们遇到麻烦,我将更新这篇文章。

此解决方案还发布项目的 git-history。不过,根据您的团队之前工作的干净程度,您可以将其过滤掉:有关如何执行此操作的 Git 文档。您应该在清理分支后执行此步骤。

该解决方案背后的想法是...

  1. 创建超级干净的分支,仅包括要部署的目录
  2. 然后将这些分支拉入新的存储库
  3. Control-Step 检查分支是否干净并准备好部署
  4. 部署

确保您有另一个备份并进行彻底测试。我们有时会使用强制命令。这在我们的存储库上完美运行,但可能会导致我尚未意识到的副作用。如果您遇到它们,请告诉我,以便我更新此条目。

执行步骤private local repository

# Assure we are on the latest stable state within our main repo
git checkout <CURRENT_STATE>

# Create a new deployment branch from HEAD
git branch <DEPLOYMENT_BRANCH> HEAD

# Enter the new branch
git checkout <DEPLOYMENT_BRANCH>
Run Code Online (Sandbox Code Playgroud)

[选项 1]:如果您打算删除目录的路径结构并将所有文件部署到新存储库的根目录中,请使用以下策略

# Filter every comment outside of this subdirectory (execute from root directory of repo)
git filter-branch -f --subdirectory-filter <DIRECTORY_PATH> -- <DEPLOYMENT_BRANCH>
Run Code Online (Sandbox Code Playgroud)

[选项2]:过滤并保留目录树

##
# Force filter-branch using the tree-filter (keeps the 
# directory-structure) while deleting all files outside    
# this directory (Check if you are on <DEPLOYMENT_BRANCH>
# first). Folders are kept, but since Git does not push 
# empty folders this is no problem

git filter-branch --tree-filter -f \
    'find . -path <DIRECTORY_PATH> -prune -o -type f -print0 | xargs -0 rm -f' \
    --prune-empty HEAD
Run Code Online (Sandbox Code Playgroud)

我们想添加master分支的.gitignore文件。

# Take master .gitignore and add it to the branch
git checkout master -- .gitignore
Run Code Online (Sandbox Code Playgroud)

您还应该更新它以忽略所有其他目录,但您的<DIRECTORY_PATH>

##
# In .gitignore:
# Ignore everything:
*

# Except for these directories:

!path/
!path/*/
!.gitignore
Run Code Online (Sandbox Code Playgroud)

暂存并提交这些更改:

git add .gitignore
git commit -m "Add .gitignore"
Run Code Online (Sandbox Code Playgroud)

通知您的开发人员同事在他们的以下位置跟踪新分支private local repositories

##
# If you would pull this branch, Git would attempt a merge it into your current HEAD.
# Do NOT pull! Instead start tracking the remote branch

git checkout --track origin/<DEPLOYMENT_BRANCH>
Run Code Online (Sandbox Code Playgroud)

在新设备上执行的步骤destination / deployment repository

克隆或创建destination / deployment repository. 在它的内部添加一个远程到我们的private local repository分支并将分支拉/合并到主分支中:

# Add remote to local private repo
git remote add local <PATH/TO/PRIVATE/REPO/.git>

git checkout master
Run Code Online (Sandbox Code Playgroud)

[选项 1]:拉取并将更改直接合并到 master 中

# Pull changes from private repo and allow unrelated histories

git pull local <DEPLOYMENT_BRANCH> --allow-unrelated-histories
Run Code Online (Sandbox Code Playgroud)

[选项2]:跟踪分支而不进行即时合并

# Track branches for more granular control
git checkout --track local/<DEPLOYMENT_BRANCH>
Run Code Online (Sandbox Code Playgroud)

部署:

# Deploy option 1: (For option 2 simply push your tracked branches)
git push origin master
Run Code Online (Sandbox Code Playgroud)