Git Mac set system command aliases and Git command aliases

Sometimes the alias of the git command is too long, and it is inconvenient to input on the command line. At this time, we can set the command alias.

Set system command aliases

Setting the system command alias can .bash_profilebe configured in the file. This file is also the place where we often configure environment variables. This file itself is invisible. Use the shortcut key comman + shift + .to view the file. In the Mac system, the file is under the user directory. /Users/sunshiyu/.bash_profileIf there is no such file, it can be created manually, but the system does not allow the creation .of files starting with . We can create it through the touch command:

touch .bash_profile

You can double-click to open the file for editing, or you can open it directly with the command:

vim ~/.bash_profile

If the command is opened, ipress the key to enter the editing state, press to escexit editing after editing, and then press :wqto save. Then enter the command source ~/.bash_profileto make the file take effect.

Command line editing is a bit cumbersome. It is recommended to double-click to open and edit directly, which is simple and fast! ! !

insert image description here

# 用于输出git提交日志
alias git-log='git log --pretty=oneline --all --graph --abbrev-commit'
# 用于输出当前目录下所有文件及基本信息
alias ll='ls -al'

insert image description here
After the configuration is completed, closing the file will take effect. At this time, reopen the terminal to verify whether the command alias is effective.

To check the command aliases of the system, use aliasthe command:

alias

insert image description here
Above you can see our configuration git-logand lltwo command aliases.

Set Git command aliases

There are two ways to set the git command alias, one is to configure it in the same way as the system command alias above .bash_profile, and the other is .gitconfigto configure it in . .gitconfigThe location of the file and .bash_profilethe same directory
insert image description here

Double-click to open the file for direct editing:

[alias]
        lg = "log --pretty=oneline --all --graph --abbrev-commit"

insert image description here
After editing, just close it to enter, and then reopen the terminal to verify whether the command alias is effective.

Above we have configured git to view the command alias of the commit log. The difference is that .bash_profilethe configuration is that the entire gitcommand has keywords git, and .gitconfigthe configuration in .gitgit

git-logThe effect of the two lgcommands is the same
insert image description here

Guess you like

Origin blog.csdn.net/SSY_1992/article/details/130669811