问题
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:
- 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.
回答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