合并时如何防止HEAD脱离? [英] How to prevent detached HEAD when merging?

查看:50
本文介绍了合并时如何防止HEAD脱离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果该操作会导致HEAD脱离,是否有任何方法可以配置Git拒绝合并?

Is there any way to config Git to reject a merge if the action will result in a detached HEAD?

我知道如何解决分离的HEAD,但是我宁愿使用git拒绝合并操作来完全避免分离的HEAD.

I know how to solve the detached HEAD, but I would rather have git to reject the merge-action to avoid the detached HEAD entirely.

发生这种情况时会发生问题:

The issue occurs when this happens:

  1. 我正在主仓库中的 develop 分支上工作,并且还在子模块存储库中进行了一些更改. develop 分支已更新,以匹配子模块的最新提交.
  2. 一个同事想将 develop 合并到 master 中,但是忘记先拉 master 上的子模块.这样会导致HEAD脱离.
  1. I am working on a develop branch in the main repo and I also comitted some changes in a submodule repository. The develop branch is updated to match the newest commit of the submodule.
  2. A colleague wants to merge develop into the master, but forgets to pull the submodule on master first. This results in a detached HEAD.

推荐答案

子模块始终处于分离状态,因为Git不会保留有关必须位于哪个分支的任何信息.

A submodule is always in detached head state because Git does not keep any information on which branch it has to be.

Git跟踪与其连接的子模块提交,因为它与提交信息一起存储.当您合并连接到不同的 submodule 提交的两个不同的分支时,Git无法在子模块上签出 branch ,这就是您拥有分离的HEAD的原因.

Git keep track of the submodule commit it is connected to because it is stored along with the commit information. When you merge two different branches that are connected to different submodule commits, Git cannot checkout a branch on the sub-module that's why you have a detached HEAD.

没有让子模块连接到分支的解决方案.

There is no solution to let your sub-modules attached to a branch.

可能的解决方法是:

https://github.com/kollerma/git-submodule-tools

这篇关于合并时如何防止HEAD脱离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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