2015-11-04 90 views
2

我写了下面的bash函数,它应该用我的用户名硬编码创建一个提交。是的,我知道git config,这只是一个最小的例子来证明我遇到的问题。内部脚本Git提交失败

# lib.sh 
function lock-commit() { 
    local commit_author="Varun Madiath <[email protected]>" 
    git commit --author="${commit_author}" "[email protected]" 
} 

但是,当我运行这个,它给了我下面的错误。在命令行上直接运行该命令不会导致错误。

[[email protected] ac-test]$ source lib.sh 
[[email protected] ac-test]$ lock-commit -m "test" 

*** Please tell me who you are. 

Run 

    git config --global user.email "[email protected]" 
    git config --global user.name "Your Name" 

to set your account's default identity. 
Omit --global to set the identity only in this repository. 

fatal: empty ident name (for <[email protected]>) not allowed 

鉴于我明确地传递了作者,我应该不需要设置user.emailuser.name配置设置。

任何想法为什么会发生这种情况,以及我如何纠正这种行为。

+0

它适用于我。尝试将脚本裁剪为只调用'lock-function'或显示您的整个脚本,或者至少如何调用'lock-function'。 – Schwern

+0

另外,你使用的是什么版本的Git?我相信' - 作者'并不总是在那里。 – Schwern

+0

我使用git版本2.6.2。我已经更新了示例,但没有使用包装器scrpit,因此我直接调用了该函数。 –

回答

1

的Git记录两个细节每个提交:在作者(这是你覆盖了什么)和提交者(这是它在你的设置寻找)。

这允许一个用户代表另一个用户提交更改,同时记录存储库中两个用户的详细信息。

+0

谢谢,这让我知道了。 原来的lib.sh也覆盖了'HOME'变量,这导致git找不到我的设置。 –