美文网首页
自动补全&别名

自动补全&别名

作者: 竹铭_ | 来源:发表于2017-12-21 10:28 被阅读0次

自动补全

适用环境(bash)
下载Git源码 Github地址
进入目录contrib/completion目录,会看到一个git-completion.bash文件。将此文件复制到你自己的用户主目录中(cp git-completion.bash ~/.git-completion.bash),并把下面一行内容添加到你的 .bash_profile 文件中:

source ~/.git-completion.bash

设置系统上所有用户都设置默认此脚本
Mac 上将此脚本复制到 /opt/local/etc/bash_completion.d 目录中,
Linux 上则复制到 /etc/bash_completion.d/ 目录中。这两处目录中的脚本,都会在 Bash 启动时自动加载

--安装完成--

使用方法连续敲击两次TAB键

$ git co<tab><tab>
commit config

GIT命令别名

有偷懒何乐而不为。
git的alias是通过配置文件进行定制的,这个配置文件能做的事情还有很多,这里只介绍alias部分,config配置文件
git的用户配置文件一般在做~/.gitconfig,当前仓库的配置文件是.git目录下的config文件。

git config添加

加上--global,配置当前用户的配置文件~/.gitconfig
可以在任何目录下执行git config --global操作

$ git config --global alias.st status

不加--global默认配置当前项目的配置文件
需要在git的目录下操作,否则会报如下的错

$ git config alise.st status
fatal: not in a git directory

git(项目)目录下

$ git config alias.st status
  • 编辑~/.gitconfig

在[alias]模块下添加,如果没有[alias]模块新建alias模块。

$ vim ~/.gitconfig
[alias]
    st = status

使用

# 查看状态
$ git status 
or 
$ git st 

# 查看分支
$ git branch 
or
$ git br 

备注: log详情参考

[alias]
    st = status
    br = branch
    cm = commit
    co = checkout
    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
    

用shell的别名

git status为例
git的别名: git st,前必须要加上git
shell别名: gs,命令是不是简单很多

下面看下shell里git别名的简单配置
Bash 内置命令 alias 用于创建一个别名,创建别名的语法:

alias name='command'

vim 打开 ~/.bash_profile, 在末尾添加以下格式的内容(下面是自己测试使用,根据自己使用习惯做相应的修改、添加等),保存退出运行 source ~/.bash_profile

alias gs="git status"
alias gc="git checkout"
alias gl="git lg"
alias gb="git branch"
alias gba="git branch -a"

使用

$ gb
* du
  master
$ gba
* du
  master
  remotes/origin/du
  remotes/origin/jeffchen
  remotes/origin/master

相关文章

网友评论

      本文标题:自动补全&别名

      本文链接:https://www.haomeiwen.com/subject/hovowxtx.html