Git Bash 别名
有些常用的指令参数非常多,每次都要输入好多参数,我们可以使用别名。Linux 系统中很多 shell,包括 bash,sh,zsh,dash 和 korn 等,不管哪种 shell 都会有一个 .bashrc 的隐藏文件,它就相当于 shell 的配置文件。Git Bash 同样也可以创建这个 .bashrc 文件。
1、打开用户目录,创建 .bashrc 文件
部分 Windows 系统不允许用户创建点号开头的文件,可以打开 git bash,执行 touch ~/.bashrc
git bash 环境中的 ~ 文件夹表示用户目录:


2、编辑 .bashrc 文件,写入一些别名
# 用于输出当前目录所有文件及基本信息
alias ll='ls -al'
# 用于查看当前文件夹的状态
# alias git status='git st'
alias git-st='git status'
alias git-log='git log --pretty=oneline'

3、重启 Git Bash,执行命令 source ~/.bashrc
此时,命令别名可以开始使用了。

要注意,等号左边必须连在一起,不能有空格,比如 git-log 不能写成 git log。另外,等号两边也不能有空格。
Ubuntu 中, .bashrc 文件是自动生成的,可以修改该文件,给 git log 添加别名:



浙公网安备 33010602011771号