问题描述
如果该操作会导致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:
- 我正在主仓库中的
develop
分支上工作,并且还在子模块存储库中进行了一些更改.develop
分支已更新,以匹配子模块的最新提交. - 一个同事想将
develop
合并到master
中,但是忘记先拉master
上的子模块.这样会导致HEAD脱离.
- I am working on a
develop
branch in the main repo and I also comitted some changes in a submodule repository. Thedevelop
branch is updated to match the newest commit of the submodule. - A colleague wants to merge
develop
into themaster
, but forgets to pull the submodule onmaster
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脱离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!