> For the complete documentation index, see [llms.txt](https://alanmpan.gitbook.io/git-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alanmpan.gitbook.io/git-learning/git/09.-she-zhi-bie-ming.md).

# 09.设置别名

顾名思义，别名就是另外一个名字，大名不好叫，取一个狗蛋的名字，好记又好叫。Git 支持命令别名，你可以通过修改配置文件或者使用命令的方式告诉 Git 你要使用别名的命令。

下面的命令是上一节的格式化提交的命令，我们现在可以将命令缩短为 `git hist`。就可以得到我们想要的效果。

```powershell
git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
```

## 通过配置文件设定别名

首先，打开终端，在终端中输入 `git config --show-origin` 查看配置文件目录，我们修改用户配置文件 gitconfig。在配置文件中添加 alias ，将别名和替代的命令写入其中并保存。

```conf
[user]
    name = aku
    email = aku@example.com
[core]
    editor = code --wait
[alias]
    hist = "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"
    ci = commit
    st = status
```

然后你就可以使用 `git hist` 来格式化输出了。

```powershell
$ git hist
* d7f681f 2023-05-05 | Added abc to the test.txt (HEAD -> master) [aku]
* 01b8702 2023-05-05 | Add first file [aku]
```

同理，我们也可以将 `commit` 设置成 `ci`。

## 通过命令设定

另外一种方式是通过 `git config`命令来实现。比如我们要将 status 命令设置为 st，可以使用如下命令。

```powershell
git config --global alias.st 'status'
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alanmpan.gitbook.io/git-learning/git/09.-she-zhi-bie-ming.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
