git push 問題:committer 'xxx (x)' does not match your user account

寫在前面

本身在本地使用多個 git 賬號,或者多我的使用一個機器部署多個 git 賬號的時候,常常會有一些衝突,今天就遇到了一個。git

問題描述

咱們多我的共同使用一個機器,昨天改配置的時候,不當心將個人用戶名和郵箱設置成了全局配置,結果今天別人在用的時候,就不能push了,提示以下錯誤信息:github

committer 'pearl (pearl@myemail.com)' does not match your user account.
the following user name and email address is currently registered.
other (other@heremail.com)

就這個問題百度 google 查了好久,從新設置了 ssh key 也還不行,仍然一直報錯,根據 git 的報錯提示執行vim

git commit --amend --reset-author

仍是不能解決問題,後來和朋友一塊兒研究他的錯誤提示信息,顯示的是 committer 不正確,而後 git log 查看日誌,發現 log 裏面有用個人用戶名提交的信息,因此決定回滾看看,因而執行segmentfault

git reset --hard logID(我提交以前的log ID)

再從新設置 ssh key,再 git push 就行了。服務器

問題總結

這個錯誤提示的緣由是因爲使用的git倉庫是基於ssh協議的(非https),須要密鑰對並創建鏈接。執行 git commit 的時候本地提交不受 ssh 協議限定,也不會檢測用戶權限,可是提交信息會以 git config user.name 爲名,因此在提交日誌中出現了非法權限提交。app

  • git pull:只須要創建ssh鏈接便可(ssh-add),因此git pull正常;ssh

  • git commit: 本地提交不受 ssh 協議限定,也不會檢測用戶權限,可是提交信息會以 git config user.name 爲名fetch

  • git push:須要創建ssh鏈接,而且會檢測用戶在遠程設置中設否具備權限(包括每一次提交者的權限),若是有權限則提交,不然顯示權限google

參考文檔:傳送門url

設置多個 ssh key

  • 不要設置全局的用戶名和郵箱,在對應的 git 項目下設置用戶信息

    git config user.name "your_username"
    git config user.email "your_email@example.com"
  • 生成 ssh key

    ssh-keygen -t rsa -C "your_email@example.com"
    
    # 看到以下提示信息後,輸入 ssh key 的文件名,如 id_rsa_username
    Generating public/private rsa key pair.
    Enter file in which to save the key (/your_home_path/.ssh/id_rsa):id_rsa_username

    而後能夠在當前目錄下看到兩個新生成的文件,一個 id_rsa_username,一個 id_rsa_username.pub。

  • 將 ssh key 添加到你的 git 項目中(如 github)

    cat id_rsa_username.pub

    粘貼上面內容到 git 項目中的 ssh key 設置的地方便可

  • 將新生成的 key 添加到 ssh-agent 中

    eval "$(ssh-agent -s)"
    Agent pid 59566
    
    cp id_rsa_username ~/.ssh/
    cp id_rsa_username.pub ~/.ssh/
    ssh-add ~/.ssh/id_rsa
  • 設置配置文件,不用每次都添加

    cd ~/.ssh
    vim config
    
    # 該文件用於配置私鑰對應的服務器
    # Default github user(first@mail.com)
    Host github.com
    HostName github.com
    User username1
    IdentityFile ~/.ssh/id_rsa_username1
    
    # second user(second@mail.com)
    # 建一個github別名,新建的賬號使用這個別名作克隆和更新
    Host github2
    HostName github.com
    User username2
    IdentityFile ~/.ssh/id_rsa_username2

附 Git 經常使用命令(參考:git經常使用命令速查表)

查看某個git命令的幫助文檔
git help [command]
查看各個文件的狀態
git status
clone一個倉庫
git clone [url]
初始化一個倉庫
git init
拉取
git pull
添加
git add [file]
提交
git commit -m "commit info"
刪除文件(從暫存區和工做區中刪除)
git rm [file]
強行刪除修改後文件(從暫存區和工做區中刪除)
git rm -f [file]
刪除文件(從暫存區中刪除,也就是在commit 以前撤銷提交)
git rm --cached [file]
移動文件或修改文件名
git mv [old-name] [new-name]
查看本地分支信息
git branch
查看遠程分支信息
git branch -r
查看全部分支信息(包括本地和遠程分支)
git branch -a
建立分支
git branch [branch_name]
切換分支
git checkout [branch_name]
合併分支到當前分支
git maege [branch_name]
刪除已經被合併的分支
git branch -d [branch-name]
刪除還未被合併的分支
git branch -D [branch_name]
合併代碼後還未提交,此時但願撤銷合併
git reset --hard HEAD
git reset --hard log_id(回滾到某一指定log位置)
查看提交日誌
git log
查看提交日誌及其對應的 diff
git log -p
查看提交日誌及其涉及的文件,以及這些文件刪除/添加了多少行
git log --stat
顯示暫存區的文件的 diff
git diff --cached
顯示未放到暫存區的文件的 diff
git diff [file]
將 diff 輸出到制定文件中
git diff > diff.txt
查看當前分支與某個分支 diff
git diff [branch_name]
查看當前工做目錄下的某個目錄與某個分支的差異
修改最後一次提交
git commit --amend
撤銷已暫存的文件
git reset HEAD [file]
撤銷對文件的修改
git checkout -- [file_name]
查看當前配置的遠程倉庫
git remote
查看當前配置的遠程倉庫和對應的地址
git remote -v
添加遠程倉庫
git remote add [remote_name] [url]
從遠程倉庫抓去數據
git fetch [remote_name] [branch_name]
推送數據到遠程倉庫
git push [remote_name] [branch_name]
查看某個遠程倉庫信息
git remote show [remote_name]
重命名遠程倉庫
git remote rename [old_name] [new_name]
刪除某個遠程倉庫
git remote rm [remote_name]
顯示已有的標籤
git tag
搜索特定tag
git tag -l [keyword]
建立輕量級標籤
git tag [tag_name]
建立含附註標籤
git tag -a [tag_name] -m [msg]
給以前的某個提交加標籤
git tag -a [tag_name] [hash]
查看某個標籤的信息
git show [tag_name]
將標籤推送到遠程倉庫
git push [remote_name] [tag_name]
將全部本地標籤一次推送到遠程倉庫
git push [remote_name] --tags
將分支b衍合入分支a
git checkout b
git rebase a
切換到另外一個分支前,你並不想把當前分支上的修改提交的話,可使用儲藏功能
git stash
顯示全部儲藏
git stash list
應用你的儲藏
git stash apply [stash_name]
還原儲藏
git stash pop
相關文章
相關標籤/搜索