2014-08-31 856 views
7

我今天爲Windows 7安裝了Git。我對Git瞭解不多,但我正在關注http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup以及YouTube上關於該主題的視頻。在視頻的用戶安裝Git和進入命令行,然後使用Git配置user.name不起作用

git config --global user.name = "My Name" 

git config --global user.email = "[email protected]" 

,它創造.gitconfig文件C:/Users/admin/.gitconfig與他們正確的價值觀。

運行上面的代碼行的三倍,這是我在該文件中得到了之後:

[user] 
    name = = 
    email = = 
    name = = 

爲什麼不工作?我遵循官方教程,我發現它適用於YouTube上的其他人,但不適合我。

回答

10

您沒有使用正確的語法:

  1. configuration不是一個Git動詞;您想用config代替。
  2. user.name"My name"之間或user.email"[email protected]"之間不應有任何等號。會發生什麼,當你運行,例如,

    git config --global user.name = "My Name" 
    

    是命令解釋=字符作爲傳遞給user.name鍵的字符串值,行("My Name")的其餘部分被忽略。這就是爲什麼你.gitconfig文件尾部含

    [user] 
        name = = 
        email = = 
    

一切,如果你使用正確的語法應該工作:

enter image description here

+1

你說得對,這是我的錯誤。在看到另一個答案後,我注意到我有多餘的'='。 – Jimsea 2014-08-31 14:49:16

3

沒有「=」的參數user.name和user.email,只需使用空格。從同一頁面 -

安裝Git時應該做的第一件事是設置您的用戶名和電子郵件地址。這是重要的,因爲每一個git的承諾使用此信息,並且它是不可改變烤成提交您繞過:

  • $混帳配置--global user.name「李四」
  • $混帳配置--global user.email [email protected]
+0

謝謝!我在那裏有冗餘的'='。這樣一個愚蠢的錯誤。 – Jimsea 2014-08-31 14:52:16

0

注:那種語法錯誤(git config --global user.email = "[email protected]")將Git的得到更好的報道2.13+(Q2 2017)

commit 9442555commit 13b9a24commit 862e80acommit afb6c30(2017年2月23日)作者:Jeff King (peff)
(由Junio C Hamano -- gitster --commit 066c38c合併,2017年3月10日)

user.email僅由cruft chars要堅持 錯誤出來,但沒有。

這意味着它將會失敗:

GIT_AUTHOR_NAME=" .;<>" git commit --allow-empty -m foo 
fatal: name consists only of disallowed characters: .;<> 

GIT_AUTHOR_EMAIL="" GIT_AUTHOR_NAME="" git commit --allow-empty -m foo 
fatal: no email was given and auto-detection is disabled