How to prevent detached HEAD when merging?

天大地大妈咪最大 提交于 2021-02-07 14:29:45

问题


Is there any way to config Git to reject a merge if the action will result in a detached 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. 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.

回答1:


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

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.

A possible solution to your issue is:

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



来源:https://stackoverflow.com/questions/48316728/how-to-prevent-detached-head-when-merging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!