本文介绍了如何防止分离HEAD中的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么git允许你承诺独立的头部?有没有可以禁用它的预提交钩子?什么目的?许多新开发人员这样做,我想找到一种方法来禁用它。

解决方案

这只能由本地git pre-commit 挂钩,所以开发人员需要创建它。使用以下内容添加 your-local-project / .git / hooks / pre-commit 文件:

 #!/ bin / sh 

if! git symbolic-ref HEAD&>的/ dev / null的;那么
echo你处于分离头部状态!提交已被阻止(使用--no-verify忽略此检查)
exit 1
fi

确保它是可执行的。



为什么要混帐阻止提交分离HEAD?分离的HEAD表示只有不存在指向正在处理的存储库状态的指针。它假设你知道你在做什么。



我宁愿调查你的团队中为什么许多开发者进入这个状态?也许他们应用了一些奇怪的流程?

Why does git allow you to commit to a detached head? Is there any pre commit hook that can disable it? What is the purpose? Many new developers do this and I'd like to find a way to disable it.

解决方案

This can be only prevented by a local git pre-commit hook, so developers would need to create it. Add the your-local-project/.git/hooks/pre-commit file with the following contents:

#!/bin/sh

if ! git symbolic-ref HEAD &> /dev/null; then
  echo "You are in a detached head state! Commit has been blocked. (Use --no-verify to bypass this check.)"
  exit 1
fi

Make sure it's executable. Credits go to svachalek

Why should git prevent commiting in detached HEAD? Detached HEAD means only that there is no pointer to the repository state you are working on. It assumes that you know what you are doing.

I would rather investigate why many developers in your team enter this state? Maybe they apply some weird worklow?

这篇关于如何防止分离HEAD中的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:23