A Tour of Magit's Status Interface
A Tour of Magit’s Status Interface
Magit Status 界面导览
Introduction
Magit is an Emacs Git client that is praised by many users. It was one of the reasons I switched to Emacs back when I stumbled across an Emacs video tutorial for the first time. I remember I was impressed by the intuitive UI/UX. In this blog post, I will go over the main Magit interface — Magit Status — and hopefully you will get to see why Magit is awesome.
简介
Magit 是一款备受推崇的 Emacs Git 客户端。当初我第一次偶然看到 Emacs 的视频教程时,它就是我转向使用 Emacs 的原因之一。我记得当时就被其直观的 UI/UX 所折服。在这篇博文中,我将带大家了解 Magit 的核心界面——Magit Status,希望你能从中领略到 Magit 的强大之处。
Magit Status
This is the entry point interface that appears when you invoke Magit. It contains quite a lot of information, even if it doesn’t seem so at first glance. The following image is an example of the Magit Status interface:
Magit Status
这是你调用 Magit 时出现的入口界面。虽然乍看之下信息量不大,但实际上它包含了非常丰富的内容。下图展示了一个 Magit Status 界面的示例:
There are two sections. The first displays four pieces of information — Head, Merge, Push, and Tag — which refer to:
- Head — the last commit of your local branch
- Merge — the remote branch you merge changes into
- Push — the remote branch you push changes to (for example, a fork you contribute to)
- Tag — the latest tag on your local branch, and how many commits you are ahead of it
界面分为两个部分。第一部分显示了四项信息——Head、Merge、Push 和 Tag,它们分别代表:
- Head — 本地分支的最新提交
- Merge — 你合并更改的目标远程分支
- Push — 你推送更改的目标远程分支(例如你贡献代码的 fork 仓库)
- Tag — 本地分支的最新标签,以及你领先该标签多少个提交
The second section contains the recent commits, which are collapsed by default to avoid clutter. Here’s what the status interface looks like when you open the recent commits section using the TAB key:
第二部分包含最近的提交记录,为了避免界面杂乱,默认是折叠的。当你使用 TAB 键展开最近提交部分时,状态界面如下所示:
This still doesn’t look like the a lot of information I described earlier, but the missing sections are just as informative: Magit only shows a section when it has something to report, and the lack of a staged or unstaged section here means nothing has changed.
这看起来依然不像我之前描述的“信息量巨大”,但未显示的部分同样具有参考价值:Magit 只会在有内容需要报告时才显示某个部分,此处没有显示“staged”(暂存)或“unstaged”(未暂存)部分,意味着当前没有任何更改。
In the following image, I modified the repository so these sections now appear:
- First, the untracked files (collapsed by default).
- Second, the changed files under the unstaged section, including their changes (also collapsed).
- Third, the staged changes, similar to the previous section but containing only what was staged.
在下图中,我修改了仓库,因此这些部分现在出现了:
- 首先是未追踪文件(Untracked files,默认折叠)。
- 其次是未暂存部分(Unstaged section)下的已更改文件,包括它们的具体变更(同样已折叠)。
- 第三是已暂存的更改(Staged changes),与上一部分类似,但仅包含已暂存的内容。
The interesting part about the Magit status interface is that it is interactive: you can stage or unstage changes, and add, delete, or hide untracked files. The list of possible interactions is far too long to cover here. To give you a better picture, it feels like piloting an airplane with the whole control panel within reach — except that here everything is at your fingertips. The following image shows that control panel:
Magit Status 界面最有趣的地方在于它的交互性:你可以暂存或取消暂存更改,还可以添加、删除或隐藏未追踪文件。可交互的操作列表太长,无法在此一一列举。为了让你有个直观的印象,这感觉就像是在驾驶飞机,整个控制面板触手可及——只不过在这里,一切都在你的指尖掌控之中。下图展示了这个控制面板:
The above image shows the Magit commands menu, which is hidden away and can be accessed using the ? key. It lists the commands available from the status interface, covering almost anything you would need, all accessible through a single key — and most are easy to remember because the first letter of the action is the shortcut key.
上图展示了 Magit 命令菜单,它平时是隐藏的,可以通过 ? 键调出。它列出了在状态界面中可用的所有命令,涵盖了你几乎需要的一切,且所有命令都只需一个按键即可触发——而且大多数命令很容易记忆,因为操作的首字母通常就是快捷键。
Looking back at the screenshots in this post, this single interface gives you the entire state of the repository while also providing all the commands you need, with excellent discoverability whether you are coming from the Git CLI or just starting out with Git through Magit.
回顾本文中的截图,这单一的界面不仅让你掌握了仓库的全部状态,还提供了你所需的所有命令。无论你是从 Git 命令行转过来的老手,还是通过 Magit 刚开始接触 Git 的新手,它都具备极佳的可发现性。
Conclusion
The design behind Magit’s status interface never ceases to amaze me. I had planned to cover several other topics, such as how Magit approaches some Git workflows, but I found myself writing a lot about just the status interface, so I decided to keep this post short. In future posts I would like to write about simple workflows like staging, committing, and navigating between branches, as well as more advanced ones like cherry-picking and rebasing (which don’t feel advanced at all when you’re using Magit).
结语
Magit 状态界面背后的设计理念总是让我惊叹不已。我原计划涵盖其他几个主题,比如 Magit 如何处理某些 Git 工作流,但我发现光是写状态界面就已经写了很多,所以我决定让这篇文章保持简短。在未来的文章中,我想写写简单的操作流程,如暂存、提交和分支切换,以及更高级的操作,如 cherry-pick 和 rebase(当你使用 Magit 时,这些操作一点也不觉得复杂)。
Still here? Good. Collect your cat. [Cat reward]
还在看吗?很好。去领你的猫吧。 [猫咪奖励]