如何更改 Gitlab 中合并的默认目标分支
How to change the default target branch for merges in Gitlab
我们在许多小组和项目中使用 Gitlab 8.10.1。许多项目恰好是其他项目的分支。
我们的问题是,每当有人打开项目的合并请求时,默认目标分支不是项目的默认分支,而是来自一个非常具体的其他项目。有没有办法以某种方式覆盖此设置?
只是为了清楚起见,我知道如何设置项目的默认分支并且这些设置看起来是正确的,但是 gitlab 在创建合并请求时似乎没有使用它们。
这个问题非常烦人,当人们不注意并以完全不同的 "master" 作为目标发出合并请求时,会导致奇怪的情况。
我们找到了此行为的根源,这是由于项目之间的关系,因为一个项目在 gitlab 中是从另一个项目分叉出来的。当删除源和分支之间的关系时,合并的默认分支是项目本身的默认分支。
现在这是我们针对这种情况的解决方案,因为我们可以忍受删除源 <->fork 关系的影响。
你需要master。然后Project setting---Default Branch ---save change
欣赏!
默认 MR 目标取决于存储库是否为 GitLab fork。
福克斯
如果存储库是 GitLab fork,则默认 MR 目标将是上游存储库的默认分支。可以通过项目设置页面上的“删除分叉关系”选项删除这种关系,之后默认 MR 目标将被确定为非分叉存储库的正常目标(如下所述)。
在撰写本文时,无法在不删除分叉关系的情况下覆盖默认 MR 目标,但已在 gitlab 问题 #14522.
中请求该功能
非分叉
如果存储库没有分支关系,则项目设置页面上的默认分支设置同时设置 (1) 默认 MR 目标和 (2) GitLab 服务器上存储库的 HEAD 引用(这决定了克隆回购时签出的分支)。请注意,由于 bug/quirk in git, problems can occur 如果曾经是默认分支的分支后来从 GitLab 中删除。
在撰写本文时,无法独立于默认分支更改默认 MR 目标,但已在 gitlab 问题 #17909.
中请求此功能
从版本 11.5.3 开始,设置发生了一些变化。来自 docs.gitlab.com:
When you create a new project, GitLab sets master as the default branch for your project. You can choose another branch to be your project’s default under your project’s Settings > Repository.
关于分叉,GitLab 13.11(2021 年 4 月)
附带了一个有趣的功能
Set default target project for merge requests in forks
After forking a project, it can be beneficial to use merge requests to make contributions to the upstream project.
Previously, GitLab assumed that merge requests from your fork project would always target the upstream project.
This can create missteps where code shouldn’t be merged upstream, or users need to make changes prior to opening the merge request.
GitLab now supports setting the default target project for merge requests that are created in fork projects.
This streamlines contributions and helps avoid mistakes for users and teams who more commonly contribute to their fork project, instead of the upstream project.
See Documentation and Issue.
我们在许多小组和项目中使用 Gitlab 8.10.1。许多项目恰好是其他项目的分支。 我们的问题是,每当有人打开项目的合并请求时,默认目标分支不是项目的默认分支,而是来自一个非常具体的其他项目。有没有办法以某种方式覆盖此设置? 只是为了清楚起见,我知道如何设置项目的默认分支并且这些设置看起来是正确的,但是 gitlab 在创建合并请求时似乎没有使用它们。 这个问题非常烦人,当人们不注意并以完全不同的 "master" 作为目标发出合并请求时,会导致奇怪的情况。
我们找到了此行为的根源,这是由于项目之间的关系,因为一个项目在 gitlab 中是从另一个项目分叉出来的。当删除源和分支之间的关系时,合并的默认分支是项目本身的默认分支。 现在这是我们针对这种情况的解决方案,因为我们可以忍受删除源 <->fork 关系的影响。
你需要master。然后Project setting---Default Branch ---save change
欣赏!
默认 MR 目标取决于存储库是否为 GitLab fork。
福克斯
如果存储库是 GitLab fork,则默认 MR 目标将是上游存储库的默认分支。可以通过项目设置页面上的“删除分叉关系”选项删除这种关系,之后默认 MR 目标将被确定为非分叉存储库的正常目标(如下所述)。
在撰写本文时,无法在不删除分叉关系的情况下覆盖默认 MR 目标,但已在 gitlab 问题 #14522.
中请求该功能非分叉
如果存储库没有分支关系,则项目设置页面上的默认分支设置同时设置 (1) 默认 MR 目标和 (2) GitLab 服务器上存储库的 HEAD 引用(这决定了克隆回购时签出的分支)。请注意,由于 bug/quirk in git, problems can occur 如果曾经是默认分支的分支后来从 GitLab 中删除。
在撰写本文时,无法独立于默认分支更改默认 MR 目标,但已在 gitlab 问题 #17909.
中请求此功能从版本 11.5.3 开始,设置发生了一些变化。来自 docs.gitlab.com:
When you create a new project, GitLab sets master as the default branch for your project. You can choose another branch to be your project’s default under your project’s Settings > Repository.
关于分叉,GitLab 13.11(2021 年 4 月)
附带了一个有趣的功能Set default target project for merge requests in forks
After forking a project, it can be beneficial to use merge requests to make contributions to the upstream project.
Previously, GitLab assumed that merge requests from your fork project would always target the upstream project.
This can create missteps where code shouldn’t be merged upstream, or users need to make changes prior to opening the merge request.GitLab now supports setting the default target project for merge requests that are created in fork projects.
This streamlines contributions and helps avoid mistakes for users and teams who more commonly contribute to their fork project, instead of the upstream project.
See Documentation and Issue.