Sna*_*unt 5 git merge fast-forward
因此,在工作中,我们正在实施一个新的、漂亮的 Git 分支策略 - 太棒了!
为了保留存储库的新(且漂亮)结构,我们希望所有合并都使用该--no-ff标志(以及--no-commit允许更好的合并提交消息的标志)完成。不过,仅仅要求大家记住,似乎有点不靠谱。有没有办法强制每个开发人员都必须与上述标志合并?
据我所知,不可能用钩子来检查这一点(因为 git 不能可靠地存储有关快进的任何信息)。我知道可以在每台开发人员机器上设置配置(通过运行git config --global merge.ff no)。如果这是解决方案,我如何确保每个开发人员都有此配置集?
这里是执行此操作的示例挂钩代码:
#!/bin/sh
# for details see here,
# http://git-scm.com/book/en/Customizing-Git-An-Example-Git-Enforced-Policy
# it seems that git on Windows doesn't support ruby, so use bash instead
# to function, put it into remote hook dir
# to disable, rename or delete file in remote hook dir
refname=$1
oldrev=$2
newrev=$3
# enforces fast-forward only pushes
check_fast_forward ()
{
all_refs=`git rev-list ${oldrev}..${newrev} | wc -l`
single_parent_refs=`git rev-list ${oldrev}..${newrev} --max-parents=1 | wc -l `
if [ $all_refs -eq $single_parent_refs ]; then
echo "This is the section for fast-forward commits ..."
exit 0
fi
}
check_fast_forward
Run Code Online (Sandbox Code Playgroud)
根据您的需要进行设置:
-eq等于Run Code Online (Sandbox Code Playgroud)if [ "$a" -eq "$b" ]
-ne不等于Run Code Online (Sandbox Code Playgroud)if [ "$a" -ne "$b" ]