本身在本地使用多個 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
不要設置全局的用戶名和郵箱,在對應的 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 help [command]
git status
git clone [url]
git init
git pull
git add [file]
git commit -m "commit info"
git rm [file]
git rm -f [file]
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
git log -p
git log --stat
git diff --cached
git diff [file]
git diff > diff.txt
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
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
git checkout b git rebase a
git stash
git stash list
git stash apply [stash_name]
git stash pop