Emoji-Log：编写 Git 提交信息的新方法
表情符 git

> 
> 使用 Emoji-Log 为你的提交添加上下文。
> 
> 
> 


![](/data/attachment/album/201903/17/233342fg3bqmjyc72mkcbg.jpg)


我是一名全职的开源开发人员，我喜欢称自己为“开源者”。我从事开源软件工作已经超过十年，并[构建了数以百计的](https://github.com/ahmadawais)开源软件应用程序。


同时我也是“<ruby> 避免重复工作 <rt>  Don’t Repeat Yourself </rt></ruby>”（DRY）哲学的忠实粉丝，并且我相信编写更好的 Git 提交消息是 DRY 的一个重要组成部分。它们具有足够的上下文关联，可以作为你开源软件的变更日志。我编写的众多工作流之一是 [Emoji-Log](https://github.com/ahmadawais/Emoji-Log/)，它是一个简单易用的开源 Git 提交日志标准。它通过使用表情符号来创建更好的 Git 提交消息，从而改善了开发人员的体验（DX）。


我使用 Emoji-Log 构建了 [VSCode Tips & Tricks 仓库](https://github.com/ahmadawais/VSCode-Tips-Tricks) 和我的 ? [紫色 VSCode 主题仓库](https://github.com/ahmadawais/shades-of-purple-vscode/commits/master)，以及一个看起来很漂亮的[自动变更日志](https://github.com/ahmadawais/shades-of-purple-vscode/blob/master/CHANGELOG.md)。


### Emoji-Log 的哲学


我喜欢（很多）表情符号，我很喜欢它们。编程、代码、极客/书呆子、开源……所有这一切本质上都很枯燥，有时甚至很无聊。表情符号帮助我添加颜色和情感。想要将感受添加到这个 2D 的、平板的、基于文本的代码世界并没有错。


相比于[数百个表情符号](https://gitmoji.carloscuesta.me/)，我学会的更好办法是让类别较小和普遍性。以下是指导使用 Emoji-Log 编写提交信息的原则：


* **必要的**
	+ Git 提交信息是必要的。
	+ 像下订单一样编写提交信息。
		- 例如，使用 ✅ **Add** 而不是 ❌ **Added**
		- 例如，使用 ✅ **Create** 而不是 ❌ **Creating**
* **规则**
	+ 少数类别易于记忆。
	+ 不多也不少
		- 例如 **? NEW** 、 **? IMPROVE** 、 **? FIX** 、 **? DOC** 、 **? RELEASE** 、 **✅ TEST**
* **行为**
	+ 让 Git 的提交基于你所采取的操作
	+ 使用像 [VSCode](https://VSCode.pro) 这样的编辑器来提交带有提交信息的正确文件。


### 编写提交信息


仅使用以下 Git 提交信息。简单而小巧的占地面积是 Emoji-Log 的核心。


* **? NEW: 必要的信息**
	+ 当你添加一些全新的东西时使用。
		- 例如 **? NEW: 添加 Git 忽略的文件**
* **? IMPROVE: 必要的信息**
	+ 用于改进/增强代码段，如重构等。
		- 例如 **? IMPROVE: 远程 IP API 函数**
* **? FIX: 必要的信息**
	+ 修复 bug 时使用，不用解释了吧？
		- 例如 **? FIX: Case converter**
* **? DOC: 必要的信息**
	+ 添加文档时使用，比如 README.md 甚至是内联文档。
		- 例如 **? DOC: API 接口教程**
* **? RELEASE: 必要的信息**
	+ 发布新版本时使用。例如， **? RELEASE: Version 2.0.0**
* **✅ TEST: 必要的信息**
	+ 发布新版本时使用。
		- 例如 **✅ TEST: 模拟用户登录/注销**


就这些了，不多不少。


### Emoji-Log 函数


为了快速构建原型，我写了以下函数，你可以将它们添加到 `.bashrc` 或者 `.zshrc` 文件中以快速使用 Emoji-Log。



```
#.# Better Git Logs.

### Using EMOJI-LOG (https://github.com/ahmadawais/Emoji-Log).

# Git Commit, Add all and Push — in one step.

function gcap() {
    git add . && git commit -m "$*" && git push
}

# NEW.
function gnew() {
    gcap "? NEW: $@"
}

# IMPROVE.
function gimp() {
    gcap "? IMPROVE: $@"
}

# FIX.
function gfix() {
    gcap "? FIX: $@"
}

# RELEASE.
function grlz() {
    gcap "? RELEASE: $@"
}

# DOC.
function gdoc() {
    gcap "? DOC: $@"
}

# TEST.
function gtst() {
    gcap "✅ TEST: $@"
}
```

要为 [fish shell](https://en.wikipedia.org/wiki/Friendly_interactive_shell) 安装这些函数，运行以下命令：



```
function gcap; git add .; and git commit -m "$argv"; and git push; end;
function gnew; gcap "? NEW: $argv"; end
function gimp; gcap "? IMPROVE: $argv"; end;
function gfix; gcap "? FIX: $argv"; end;
function grlz; gcap "? RELEASE: $argv"; end;
function gdoc; gcap "? DOC: $argv"; end;
function gtst; gcap "✅ TEST: $argv"; end;
funcsave gcap
funcsave gnew
funcsave gimp
funcsave gfix
funcsave grlz
funcsave gdoc
funcsave gtst
```

如果你愿意，可以将这些别名直接粘贴到 `~/.gitconfig` 文件：



```
# Git Commit, Add all and Push — in one step.
cap = "!f() { git add .; git commit -m \"$@\"; git push; }; f"

# NEW.
new = "!f() { git cap \"? NEW: $@\"; }; f"
# IMPROVE.
imp = "!f() { git cap \"? IMPROVE: $@\"; }; f"
# FIX.
fix = "!f() { git cap \"? FIX: $@\"; }; f"
# RELEASE.
rlz = "!f() { git cap \"? RELEASE: $@\"; }; f"
# DOC.
doc = "!f() { git cap \"? DOC: $@\"; }; f"
# TEST.
tst = "!f() { git cap \"✅ TEST: $@\"; }; f"
```

### Emoji-Log 例子


这里列出了一些使用 Emoji-Log 的仓库：


* [Create-guten-block toolkit](https://github.com/ahmadawais/create-guten-block/commits/)
* [VSCode Shades of Purple theme](https://github.com/ahmadawais/shades-of-purple-vscode/commits/)
* [Ahmad Awais' GitHub repos](https://github.com/ahmadawais) （我的最新的仓库）
* [CaptainCore CLI](https://github.com/CaptainCore/captaincore-cli/commits/) （WordPress 管理工具）
* [CaptainCore GUI](https://github.com/CaptainCore/captaincore-gui/commits/) （WordPress 插件）


你呢？如果你的仓库使用 Emoji-Log，请将这个 [Emoji-Log 徽章](https://on.ahmda.ws/rOMZ/c)放到你的 README 中，并给我发送一个[拉取请求](https://github.com/ahmadawais/Emoji-Log/pulls)，以让我可以将你的仓库列在这里。




---


via: <https://opensource.com/article/19/2/emoji-log-git-commit-messages>


作者：[Ahmad Awais](https://opensource.com/users/mrahmadawais) 选题：[lujun9972](https://github.com/lujun9972) 译者：[MjSeven](https://github.com/MjSeven) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
I'm a full-time open source developer—or, as I like to call it, an ? open sourcerer. I've been working with open source software for over a decade and [built hundreds](https://github.com/ahmadawais) of open source software applications.

I also am a big fan of the Don't Repeat Yourself (DRY) philosophy and believe writing better Git commit messages—ones that are contextual enough to serve as a changelog for your open source software—is an important component of DRY. One of the many workflows I've written is [Emoji-Log](https://github.com/ahmadawais/Emoji-Log/), a straightforward, open source Git commit log standard. It improves the developer experience (DX) by using emoji to create better Git commit messages.

I've used Emoji-Log while building the [VSCode Tips & Tricks repo](https://github.com/ahmadawais/VSCode-Tips-Tricks), my ? [Shades of Purple VSCode theme repo](https://github.com/ahmadawais/shades-of-purple-vscode/commits/master), and even an [automatic changelog](https://github.com/ahmadawais/shades-of-purple-vscode/blob/master/CHANGELOG.md) that looks beautiful.

## Emoji-Log's philosophy

I like emoji (which is, in fact, the plural of emoji). I like 'em a lot. Programming, code, geeks/nerds, open source… all of that is inherently dull and sometimes boring. Emoji help me add colors and emotions to the mix. There's nothing wrong with wanting to attach feelings to the 2D, flat, text-based world of code.

Instead of memorizing [hundreds of emoji](https://gitmoji.carloscuesta.me/), I've learned it's better to keep the categories small and general. Here's the philosophy that guides writing commit messages with Emoji-Log:

**Imperative**- Make your Git commit messages imperative.
- Write commit message like you're giving an order.
- e.g., Use ✅
**Add**instead of ❌**Added** - e.g., Use ✅
**Create**instead of ❌**Creating**

- e.g., Use ✅

**Rules**- A small number of categories are easy to memorize.
- Nothing more, nothing less
- e.g.
**? NEW**,**? IMPROVE**,**? FIX**,**? DOC**,**? RELEASE**, and**✅ TEST**

- e.g.

**Actions**- Make Git commits based on actions you take.
- Use a good editor like
[VSCode](https://VSCode.pro)to commit the right files with commit messages.


## Writing commit messages

Use only the following Git commit messages. The simple and small footprint is the key to Emoji-Logo.

**? NEW: IMPERATIVE_MESSAGE**- Use when you add something entirely new.
- e.g.,
**? NEW: Add Git ignore file**

- e.g.,

- Use when you add something entirely new.
**? IMPROVE: IMPERATIVE_MESSAGE**- Use when you improve/enhance piece of code like refactoring etc.
- e.g.,
**? IMPROVE: Remote IP API Function**

- e.g.,

- Use when you improve/enhance piece of code like refactoring etc.
**? FIX: IMPERATIVE_MESSAGE**- Use when you fix a bug. Need I say more?
- e.g.,
**? FIX: Case converter**

- e.g.,

- Use when you fix a bug. Need I say more?
**? DOC: IMPERATIVE_MESSAGE**- Use when you add documentation, like README.md or even inline docs.
- e.g.,
**? DOC: API Interface Tutorial**

- e.g.,

- Use when you add documentation, like README.md or even inline docs.
**? RELEASE: IMPERATIVE_MESSAGE**- Use when you release a new version. e.g.,
**? RELEASE: Version 2.0.0**

- Use when you release a new version. e.g.,
**✅ TEST: IMPERATIVE_MESSAGE**- Use when you release a new version.
- e.g.,
**✅ TEST: Mock User Login/Logout**

- e.g.,

- Use when you release a new version.

That's it for now. Nothing more, nothing less.

## Emoji-Log functions

For quick prototyping, I have made the following functions that you can add to your **.bashrc**/**.zshrc** files to use Emoji-Log quickly.

```
#.# Better Git Logs.
### Using EMOJI-LOG (https://github.com/ahmadawais/Emoji-Log).
# Git Commit, Add all and Push — in one step.
function gcap() {
git add . && git commit -m "$*" && git push
}
# NEW.
function gnew() {
gcap "? NEW: $@"
}
# IMPROVE.
function gimp() {
gcap "? IMPROVE: $@"
}
# FIX.
function gfix() {
gcap "? FIX: $@"
}
# RELEASE.
function grlz() {
gcap "? RELEASE: $@"
}
# DOC.
function gdoc() {
gcap "? DOC: $@"
}
# TEST.
function gtst() {
gcap "✅ TEST: $@"
}
```


To install these functions for the [fish shell](https://en.wikipedia.org/wiki/Friendly_interactive_shell), run the following commands:

```
function gcap; git add .; and git commit -m "$argv"; and git push; end;
function gnew; gcap "? NEW: $argv"; end
function gimp; gcap "? IMPROVE: $argv"; end;
function gfix; gcap "? FIX: $argv"; end;
function grlz; gcap "? RELEASE: $argv"; end;
function gdoc; gcap "? DOC: $argv"; end;
function gtst; gcap "✅ TEST: $argv"; end;
funcsave gcap
funcsave gnew
funcsave gimp
funcsave gfix
funcsave grlz
funcsave gdoc
funcsave gtst
```


If you prefer, you can paste these aliases directly in your **~/.gitconfig** file:

```
# Git Commit, Add all and Push — in one step.
cap = "!f() { git add .; git commit -m \"$@\"; git push; }; f"
# NEW.
new = "!f() { git cap \"? NEW: $@\"; }; f"
# IMPROVE.
imp = "!f() { git cap \"? IMPROVE: $@\"; }; f"
# FIX.
fix = "!f() { git cap \"? FIX: $@\"; }; f"
# RELEASE.
rlz = "!f() { git cap \"? RELEASE: $@\"; }; f"
# DOC.
doc = "!f() { git cap \"? DOC: $@\"; }; f"
# TEST.
tst = "!f() { git cap \"✅ TEST: $@\"; }; f"
```


## Emoji-Log examples

Here's a list of repos that use Emoji-Log.

[Create-guten-block toolkit](https://github.com/ahmadawais/create-guten-block/commits/)[VSCode Shades of Purple theme](https://github.com/ahmadawais/shades-of-purple-vscode/commits/)[Ahmad Awais' GitHub repos](https://github.com/ahmadawais)(my latest repos)[CaptainCore CLI](https://github.com/CaptainCore/captaincore-cli/commits/)(WordPress management toolkit)[CaptainCore GUI](https://github.com/CaptainCore/captaincore-gui/commits/)(WordPress plugin)**You?**If your repo uses Emoji-Log, add the[Emoji-Log badge](https://on.ahmda.ws/rOMZ/c)to your README and send me a[pull request](https://github.com/ahmadawais/Emoji-Log/pulls)so I can list your repo in the repo.

## 12 Comments