git config

 git config 文件位置

具体某个仓库私有的git config文件在.git目录下

linux上global git config文件在~/.gitconfig

windows上global git config文件在C:\Users\<user_name>\.gitconfig

在命令行串口中可以通过如下命令列出查看所有git config 项

>> git config --list

>> git config --global --list

 

git config user.name/email

git中每次commit时git都会自动在这次commit中添加提交人信息,用来mark这次commit是谁提交的,并记录该人的邮箱,否则你的同时看到commit历史记录他怎么知道这是谁提交的呢。
所以git要求必须要进行用户名和用户邮箱设置,否则不允许你提交。设置方式如下:

Global 设置

>> git config --global user.name yourName

>> git config --global user.email yourEmail

一旦这样设置后,在该计算机账户下所有仓库使用git commit的时候git都默认用这一组邮箱和用户名来mark你的commit信息

但是如果在同一个计算机账户下由于有多个人在工作或其他原因导致你对某个项目提交的时候需要用单独的邮箱和用户名提交怎么办呢?git中允许你正对单独的project进行设置,设置方法如下:

当前Project设置

>> git config user.name yourName

>> git config user.email yourEmail

上面的命令如果不跟yourName或者yourEmail参数的话就是查询,跟了参数的话就是设置命令

 

Git 删除或修改本地保存的账号密码

配置Git记住用户名和密码

>> git config --global credential.helper store

配置Git清除用户名和密码

>> git config --global --unset credential.helper

Win10中删除或修改已保存的账号和密码

Win10删除或修改本地Git保存的账号密码

 

修改默认编辑器

关于默认编辑器最好是安装git之前你就已经安装了相应的编辑器比如notepad++或VS Code,这样就可以在安装git的时候直接在安装配置界面中配置。如果在安装完了git后再要修改默认编辑器参照如下:

在git中设置默认使用的文本编辑器为notepad++

$ git config --global core.editor notepad++

设置成功会如下显示。

$ git config --global core.editor 
notepad++

有的时候设置不成功,提交的时候不弹出notepad++,可以再使用如下命令试试

git config --global core.editor "'D:\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin '$*'"

将默认编辑器修改为VS Code

git config --global core.editor "code -w"

设置成功会如下显示。

$ git config --global core.editor
code -w

设置了编辑器后,commit时编辑器打开了但是bash中提示提交取消

$ git commit
Aborting commit due to empty commit message.

查找到StackOverflow上说法

When you set an editor in the configuration of Git, make sure to pass the parameter "-w" to force Git to wait your commit message that you would type on your custom editor.

相应的做法是设置编辑器的时候加上-w参数

For Visual studio Code

git config --global core.editor "code -w"

For atom

git config --global core.editor "atom -w"

For sublime

git config --global core.editor "subl -w"

但是有时候即我们加了-w参数也不成功或者说会报如下错误:

$ git config --global core.editor "Code -w"
 warning: core.editor has multiple values
 error: cannot overwrite multiple values with a single value
        Use a regexp, --add or --replace-all to change core.editor.

这个时候需要重置git的编辑器设置然后重新设置编辑器

git config --global --unset-all core.editor
git config  --unset-all core.editor
git config --global core.editor "code -w"

这样操作之后终于把问题解决了,设置成功后提交时会提示如下:

$ git commit
hint: Waiting for your editor to close the file...

 

posted @ 2019-09-16 22:19  蛮哥哥  阅读(1744)  评论(0编辑  收藏  举报