代码之家  ›  专栏  ›  技术社区  ›  Ray

在Git中,当分支到除master分支以外的任何其他分支时,添加警告的最佳方法是什么

git
  •  0
  • Ray  · 技术社区  · 6 年前

    除了 master 在我的日常工作流程中(可能偶尔会在发布分支上修复错误等等)。通过重新定位和合并挤压,您可能会得到一个剩余的分支,您真的不想意外地启动一个新分支,否则当您尝试将新分支合并到 (没有意识到你最初没有从 主人

    如果当前工作的分支不是 ,就像 "Warning: Hey, you're not branching off master--think about it!"

    1 回复  |  直到 6 年前
        1
  •  1
  •   Mauricio Machado    6 年前

    这看起来像是一个结账前的钩子。 不是实际的代码,但是,您可以执行以下操作:

    branch=$(git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/\1/p')
    if [ $branch != master ]; then
        << do_you_want_to_checkout_anyway? >>
        if [ user_answered_ok ]; then exit 0
        else exit 1
        fi
    fi
    

    .git/hooks

    供参考: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks