git config 常用配置
2018-01-10 10:42
471 查看
git config 常用配置
用了2年git了,除了当时入门时一周看完并基本掌握了 廖雪峰的Git教程 上面的知识,之后这2年中,在我们那个小Team里,我的
git 能力还算上流了,也就再也没有仔细看过 git 相关教程了。
近来换了份工作,熟悉新环境的这段时间又简单翻了下 git 相关教程,赫然发现自己知道的真是太少了,连最基本的 git config 有哪些,都有什么用都不清楚......
在以往使用git时,都只接触到了下面这两组config命令:
却不知原来还有一组:
git 在需要用户输入额外信息时,会调用系统指定的默认编辑器,一般可能是 vi 或者 vim。
如果你偏爱其他的编辑器,比如Emacs,那么就可以这样设置:
会用git的人,肯定知道 git diff,但并不一定知道这个 diff 命令调用的差异分析工具也是可以改的,而且git能支持的差异分析工具很多,如:kdiff3、tkdiff、meld、xxdiff、emerge、vimdiff、gvimdiff、ecmerge、opendiff等等。
假如我们要改用vimdiff,我们可以这样设置:
我们在用git的时候,很多时候都是用的命令行形式的,不仅要记得住大量命令,还要能灵活进行组合,这就很是头大了,正因为此,命令别名的重要性就出来了。但与其说是别名,倒不如说是另类的简写形式。
别名的配置也需要使用config命令,比如给 git status 设置别名 st:
这样我们以后使用的时候,直接用 git st 就可以做 git status 的事了。
再来一个从 廖雪峰的Git教程 上看来的,很牛掰的,我自己也在用的一个别名:
执行 git lg 的效果是这样的,惊不惊喜,意不意外?
20170605更新:
为了更方便查看,本人对上面的lg命令进行了简单的修改:
其中,
%h 表示提交id;
%cr 表示提交时间;
%an 表示提交人;
%d 表示 分支、tag、HEAD 等信息;
%s 表示提交的信息。
效果如下:
要查看已经存在的配置信息,我们可以用如下命令:
其中我的Windows版Git,执行git config --list是这个效果:
如果要单独设置上面这些项,可以用前面几点提到的方法进行设置,比如:
虽然 Git 是个强大的工具,但俗话说“磨刀不误砍材工”,我们在使用前对它进行一些合理的配置,将会大大提升工作效率。
用了2年git了,除了当时入门时一周看完并基本掌握了 廖雪峰的Git教程 上面的知识,之后这2年中,在我们那个小Team里,我的
git 能力还算上流了,也就再也没有仔细看过 git 相关教程了。
近来换了份工作,熟悉新环境的这段时间又简单翻了下 git 相关教程,赫然发现自己知道的真是太少了,连最基本的 git config 有哪些,都有什么用都不清楚......
1、配置用户名和邮箱
在以往使用git时,都只接触到了下面这两组config命令:# 查看或配置当前项目,config文件在项目目录下:.git/config git config user.name [NAME] git config user.email [EMAIL] # 查看或配置当前用户,config文件在用户目录下:~/.gitconfig git config --global user.name [NAME] git config --global user.email [EMAIL]
却不知原来还有一组:
# 查看或配置当前系统,config文件在系统目录下:/etc/gitconfig git config --system user.name [NAME] git config --system user.email [EMAIL]
2、配置默认文本编辑器
git 在需要用户输入额外信息时,会调用系统指定的默认编辑器,一般可能是 vi 或者 vim。如果你偏爱其他的编辑器,比如Emacs,那么就可以这样设置:
git config [--system|global] core.editor emacs
3、配置差异分析工具
会用git的人,肯定知道 git diff,但并不一定知道这个 diff 命令调用的差异分析工具也是可以改的,而且git能支持的差异分析工具很多,如:kdiff3、tkdiff、meld、xxdiff、emerge、vimdiff、gvimdiff、ecmerge、opendiff等等。假如我们要改用vimdiff,我们可以这样设置:
git config [--system|global] merge.tool vimdiff
4、配置命令别名
我们在用git的时候,很多时候都是用的命令行形式的,不仅要记得住大量命令,还要能灵活进行组合,这就很是头大了,正因为此,命令别名的重要性就出来了。但与其说是别名,倒不如说是另类的简写形式。别名的配置也需要使用config命令,比如给 git status 设置别名 st:
git config --global alias.st status
这样我们以后使用的时候,直接用 git st 就可以做 git status 的事了。
再来一个从 廖雪峰的Git教程 上看来的,很牛掰的,我自己也在用的一个别名:
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
执行 git lg 的效果是这样的,惊不惊喜,意不意外?
20170605更新:
为了更方便查看,本人对上面的lg命令进行了简单的修改:
log --color --graph --pretty=format:'%C(bold red)%h%C(reset) - %C(bold green)(%cr)%C(bold blue)<%an>%C(reset) -%C(bold yellow)%d%C(reset) %s' --abbrev-commit
其中,
%h 表示提交id;
%cr 表示提交时间;
%an 表示提交人;
%d 表示 分支、tag、HEAD 等信息;
%s 表示提交的信息。
效果如下:
5、查看已有配置信息
要查看已经存在的配置信息,我们可以用如下命令:git config [--system|global] --list
其中我的Windows版Git,执行git config --list是这个效果:
core.symlinks=false core.autocrlf=input core.fscache=true color.diff=auto color.status=auto color.branch=auto color.interactive=true help.format=html http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt diff.astextplain.textconv=astextplain rebase.autosquash=true credential.helper=manager gui.fontdiff=-family "Microsoft YaHei UI" -size 10 -weight normal -slant roman -underline 0 -overstrike 0 gui.encoding=utf-8 user.email=shawn194@qq.com user.name=ShawnXia alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit color.status=auto
如果要单独设置上面这些项,可以用前面几点提到的方法进行设置,比如:
# status 高亮模式为 auto git config --global color.status auto # branch 高亮模式为 auto git config --global color.branch auto # ui 高亮模式为 auto git config --global color.ui auto
虽然 Git 是个强大的工具,但俗话说“磨刀不误砍材工”,我们在使用前对它进行一些合理的配置,将会大大提升工作效率。
相关文章推荐
- Maven--pom.xml常用配置
- spring boot之spring mvc常用配置--路径匹配参数设置(7)
- Gradle常用配置-版本号自增
- maven的安装以及常用的配置
- 常用配置管理工具比较
- Java程序员从笨鸟到菜鸟之(五十三)细谈Hibernate(四)Hibernate常用配置文件详解
- pycharm快捷键、常用设置、配置管理
- apache常用配置
- PHPSTORM/IntelliJ IDEA 常用 设置配置优化 - meetrice
- struts中的常用配置
- 一些linux常用的安全配置
- kafka broker的常用配置
- Tomcat 5常用优化和配置
- 配置安装Python+安装常用函数库——DAY1_2015_05_20
- 项目部署、配置、查错常用到的Linux命令
- Log4j 常用配置
- Eclipse中常用的快捷键和模板配置
- 常用基本配置
- pycharm快捷键、常用设置、配置管理
- WAMP常用环境配置