git多账户跨平台管理 git 的配置分system, global, local三个等级global在用户目录 /.gitconfig里面可以配置当前用户的所有仓库local在某个仓库的repository/.git/config里面只对当前repository有效Windows系统里面每行结尾用回车(CR)换行(LF)Linux系统中每行结尾用换行(LF)这样会出现本来代码没有动但是git显示有改动的情况。我们上传到版本控制系统里面的换行符一般都都是统一用LF的。因此电脑端这样配置gitconfig--globalcore.autocrlftrue# 此命令可以在提交时把结束符CRLF转换成LF而在拉取代码时把LF转换成CRLF。建议windows机器这样配置gitconfig--globalcore.autocrlf input# 此命令只会在提交文件时对CRLF进行LF转换拉取时不转换。建议linux机器这样配置gitconfig--globalcore.autocrlffalse# 此命令在提交和拉取时均不转换配置好后可以用以下命令来检查global配置gitconfig--global--list另外我们通常一台电脑只有一个用户这个时候你可以设置global 用户和邮箱。然后有时候我们在一台服务器上会有多人使用这个时候如何设置git呢。清除globalgitconfig--global--unsetuser.namegitconfig--global--unsetuser.emailssh-keygen-trsa-Cuser1gmail.com-f~/.ssh/id_rsa_1# 设置用户1的ssh-key# 或者用更快更安全的命令ssh-keygen-ted25519-Cuser1gmail.com-f~/.ssh/id_ed25519_1 ssh-keygen-trsa-Cuser2gmail.com-f~/.ssh/id_rsa_2# 设置用户2的ssh-key# 或者用更快更安全的命令ssh-keygen-ted25519-Cuser2gmail.com-f~/.ssh/id_ed25519_2这个时候你在/.ssh下面可以发现有两对公钥和私钥。然后在/ssh下面新建config文件# user1Host user1.github.com HostName github.com UsergitIdentityFile ~/.ssh/id_rsa_1# user2Host user2.github_pro HostName github.com UsergitIdentityFile ~/.ssh/id_rsa_2Host是可以随便取的别名hostname是实际真实的服务器地址。然后当user1 想要ssh clone 他自己的仓库的时候就不能用默认名称了, 比如gitclone gitgithub.com:ArnaudRinquin/atom-zentabs.git这个时候要改为如下命令git会通过config文件里面的host别名去取对应的ssh key文件gitclone gituser1.github.com:ArnaudRinquin/atom-zentabs.git#user1.github.com就是我们在config里面配置的host别名这个时候你查看这个repository的git配置文件就会发现remote就是user1的host。cdatom-zentabscd.gitvimconfig# 然后你还要在这个仓库里面添加local的用户名和邮箱gitconfig--localuser.nameuser1gitconfig--localuser.emailuser1gmail.com然后你可以查看这个repository的配置。当然必须在这个repository目录里面才可以否则会提示找不到配置文件。gitconfig--local--list