阻止 git 合并到 master 分支

发布于 2024-12-16 13:24:43 字数 259 浏览 3 评论 0原文

我正在使用分支来创建和部署平台的自定义实例。这些实例通常作为“主”分支的分支开始,进行一些定制,部署到测试和生产中,最后归档。

如果将新功能或错误修复添加到主库中,我希望能够将它们获取/合并到我的项目实例(分支)中,但我几乎不想将更改从分支合并回主库。最近发生了这种错误,并造成了一些严重的头痛。用于更新存储库的 git pull 将所有内容合并到主分支中,然后被推回到主存储库中。

有没有什么简单的方法可以禁止合并回master?或者至少需要一些 --force 标志?

I am using branching to create and deploy custom instances of out platform. These instances usually start as a branch from the 'master' branch, get customized somewhat, get deployed into testing and production, and finally archived.

If new features or bug fixes are added into the master I would like to be able to fetch/merge them into my project instances (branches), but I almost never want to merge back changes from the branches to the master. This occurred recently by mistake and has created some serious headaches. A git pull to update a repository merged everything into the master branch and then was pushed back into the main repo.

Is there any easy way to forbid merging back into the master? Or at least requiring some --force flag?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

¢蛋碎的人ぎ生 2024-12-23 13:24:43

您可以通过禁止任何人推送 master 分支来确保不会从其他分支合并到 master 中。一个有权威的人可以做到这一点。 Gitolite 可以让你微调对分支的访问。您还可以编写自己的服务器端挂钩并拒绝主分支的更新,除非您是特定用户。

You can ensure no merging into the master from other branches by forbidding anyone to push the master branch. A person with authority can do that. Gitolite is something that allows you to finely tune access to branches. You can also write your own server side hooks and reject updating of the master branch unless you are a specific user.

安人多梦 2024-12-23 13:24:43

Git 非常乐意与多个远程存储库一起工作。

我建议为每个自定义实例使用一个远程存储库。这不会改变您的工作流程,因为 Git 可以将任何两个分支合并在一起,无论来源如何。

要使用“主远程”中的错误修复来更新“自定义实例”,您需要输入类似的内容

git checkout <custom-branch>
git fetch main
git merge main/master

,其中 main 是您称为 master 的远程存储库(I更改名称以避免分支和远程分支之间的混淆)

对于本地分支,不要指定main作为远程跟踪分支,而是指定特定于实例的远程分支。即每个自定义实例一个远程存储库。

要将更改推送到自定义实例,请使用

git push

在极少数情况下,您需要将更改推送到上游“master”分支,请使用

git push main

Git is quite happy to work with multiple remote repositories.

I would recommend using one remote repository for each custom instance. This would not change your workflow, as Git can merge any two branches together regardless of origin.

To update a "custom instance" with bug fixes from your "master remote" you'd type something like

git checkout <custom-branch>
git fetch main
git merge main/master

where main is the remote repository you are referring to as master(I changed the name to avoid confusion between a branch and a remote)

For your local branches, do not specify main as the remote tracking branch, instead specify an instance-specific remote. i.e. one remote repository per custom instance.

To push changes to your custom instance, use

git push

In the rare case where you need to push changes upstream to the "master" branch use

git push main
柒七 2024-12-23 13:24:43

如果你只是想避免合并到 master 中,你可以使用 pre-merge hook 来禁止它。

If you just want to avoid merging into master, you could use pre-merge hook to forbid it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文