我们公司使用许多定制的开源项目。每当我向上游分支机构捐款时,我都会更改为使用我的个人电子邮件地址/名称。有什么办法让每个分支都有gitconfig吗?

例如我想要的是

[remote 'gerrit']
name = 'Personal Name'

[branch 'origin']
name = 'Name in company'

最佳答案

您可以为此使用结帐后 Hook 。运行

$ touch .git/hooks/post-checkout
$ chmod a+x .git/hooks/post-checkout

将内容添加到post-checkout脚本(必要时编辑名称和分支)
#!/bin/bash
# $3 "0" - checking out file. "1" - checking out branch.
[[ "$3" == "0" ]] && exit 0
branch=$(git status --short -b | cut -d' ' -f2-)
case $branch in
  gerrit*)
    git config user.name "Personal Name"
    echo "changed user.name to Personal Name"
    ;;
  master*)
    git config user.name "Company Name"
    echo "changed user.name to Company Name"
    ;;
  *)
    echo "Some other branch, what should user.name be?"
    ;;
esac

09-04 14:33
查看更多