Mak*_*e42 6 git access-control git-flow
前几天我读了https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow,我有一个问题.
如果在项目中使用功能分支或Gitflow分支工作流:是否存在用户将功能分支作为跟踪功能分支推送到源的选项发出拉取请求,并且只有项目的维护者才能合并跟踪功能分支进入主(功能分支工作流)或开发(Gitlow分支工作流)?
换句话说:是否可以将分支分配给用户,以便如果不想让事情过于复杂但仍然保证代码审查能够保证master/develop分支免受新手的影响,那么人们就不会立即需要分岔工作流程?
远程 git 服务,如 github、bitbucket、gitlab、vsts 等,具有“保护”分支的能力,以防止直接推送到它们或删除分支。如果你想在本地计算机上模拟类似的东西,你可以使用 git hooks:https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
防止提交到 master 的示例:https ://gist.github.com/aaronhoffman/ffbfd36928f9336be2436cffe39feaec
预提交文件:
#!/bin/sh
# prevent commit to local master branch
branch=`git symbolic-ref HEAD`
if [ "$branch" = "refs/heads/master" ]; then
echo "pre-commit hook: Can not commit to the local master branch."
exit 1
fi
exit 0
Run Code Online (Sandbox Code Playgroud)
预推送文件:
#!/bin/sh
# Prevent push to remote master branch
while read local_ref local_sha remote_ref remote_sha
do
if [ "$remote_ref" = "refs/heads/master" ]; then
echo "pre-push hook: Can not push to remote master branch."
exit 1
fi
done
exit 0
Run Code Online (Sandbox Code Playgroud)