atom 中首次使用git_使用Atom获得更好的Git提交消息

何高歌
2023-12-01

atom 中首次使用git

by Hasit Mistry

通过Hasit Mistry

使用Atom获得更好的Git提交消息 (Get Better Git Commit Messages with Atom)

Recently, I came across two enlightening posts about writing better Git commit messages. These posts give suggestions about how a well structured commit message should look like, and provide clear examples.

最近,我遇到了两个有关编写更好的Git提交消息的启发性文章。 这些帖子提供了有关结构良好的提交消息外观的建议,并提供了清晰的示例。

These two blog posts made me go back to my repositories and read my commit messages. And to be honest, I felt a little ashamed of my past then.

这两个博客文章使我返回到存储库并阅读了提交消息。 老实说,那时我对自己的过去感到有些ham愧。

You may ask, “why are commit messages even important?” If you find yourself asking that question, you are like the one-week-younger version of me.

您可能会问,“为什么提交消息甚至很重要?” 如果您发现自己在问这个问题,那就像是我一个星期的孩子。

Just to give you an idea, Figure 1 shows some of the commit messages from my project licensethis. I promise that the code is much better than the commit messages.

为了给您一个想法,图1显示了我的项目licensethis中的一些提交消息。 我保证代码比提交消息要好得多。

It’s unsurprising how little these commit messages actually tell me about my past work. That’s because I didn’t take writing them seriously.

这些提交消息实际上告诉我有关我过去的工作的信息不足为奇。 那是因为我没有认真对待它们。

In order to actually understand which changes each commit contributed, I had to go into each commit and read the changes line-by-line. This is tedious to say the least.

为了真正了解每个提交所做的更改,我必须进入每个提交并逐行阅读更改。 至少可以说这很乏味。

At the time of authoring these commit messages, I invariably blurted out whatever made sense to me at that moment, with no consideration of how I — or anyone else for that matter — would understand the text at a later stage.

在编写这些提交消息时,我总是脱口而出当时对我有意义的任何内容,而没有考虑我-或其他人在以后的阶段将如何理解文本。

First, let’s synthesize all the information we’ve absorbed from the above-mentioned blog posts. Then I’ll give working tips on how Atom can be used as a tool for writing better commit messages for myself and others who are interested in doing the same.

首先,让我们综合从上述博客文章中吸收的所有信息。 然后,我将提供一些工作提示,说明如何将Atom用作为自己和其他有兴趣这样做的人编写更好的提交消息的工具。

Note that I am not going to write about how to write a good commit message. Chris Beams’s wonderful post on How to Write a Git Commit Message explains just that and more in seven rules.

请注意,我不会写有关如何编写好的提交消息的文章。 克里斯·比姆斯 ( Chris Beams )在有关如何编写Git提交消息的精彩文章中,用七个规则对此进行了解释。

Before we begin, let us look at this following text block to understand what is considered as a properly-structured, purposeful, and well-written commit message:

在开始之前,让我们看一下下面的文本块,以了解什么被认为是结构正确,有目的且写得很好的提交消息:

# Subject in (preferably) less than 50 charactersThis is the subject of this commit message
# Body in greater detailThis is the body of this commit message. The body is written after the subject line with one blank line in between. The blank line is used by various tools (such as 'git log', 'git show', etc.) to differentiate subject from body. Further paragraphs are also separated by blank lines.
Explain the problem being solved by this commit. More importantly, explain why these changes are being made, as opposed to how. The 'why' part is your responsibility, the 'how' part is code's responsibility.
- You can also use bullets like this.- Or, like this.

Some great examples of such commit messages can be found over at the Linux and Git repositories on GitHub.

可以在GitHub上LinuxGit存储库中找到此类提交消息的一些很好的示例。

Now, it is understandable that not every commit brings big changes to the repository. Some commits would be for fixing typos, and others for changing line order or indentation. In such cases, a subject line by itself should suffice.

现在,可以理解的是,并非每次提交都会对存储库带来重大变化。 一些提交用于修复错别字,而其他提交则用于更改行序或缩进。 在这种情况下,主题行本身就足够了。

Atom is a text editor that I use for everything! I use it to take notes in class, complete writing assignments in Markdown (unless I absolutely require the super powers of MS Word), and for programming projects on a daily basis.

Atom是我用于所有操作的文本编辑器! 我用它在课堂上做笔记,在Markdown中完成写作作业(除非我绝对需要MS Word的超级能力),以及用于日常项目编程。

I keep tweaking Atom little-by-little every time I learn something new, it’s fun to watch my config files slowly grow in size.

每次学习新知识时,我都会不断地对Atom进行微调,很有趣的一点是,我的配置文件的大小逐渐变大。

So let us start by setting Atom as our default commit editor for git, and checking if the same has happened correctly using the following commands in your terminal:

因此,让我们从将Atom设置为git的默认提交编辑器开始,并使用以下命令在终端中检查是否正确发生了该操作:

git config --global core.editor "atom --wait"
git config --get core.editor
# Which should give you the output: atom --wait

根据其长度更改主题线的颜色 (Change the color of the subject line according to its length)

First, we will set up Atom so that it changes the color of the subject line to orange if the length exceeds 50 characters and to red if the length exceeds 65 characters. You can read more about git integrations for Atom at Git Integration.

首先,我们将设置Atom,以便如果长度超过50个字符,则将主题行的颜色更改为橙​​色,如果长度超过65个字符,则将其更改为红色。 您可以在Git Integration上了解有关Atom的git集成的更多信息。

Open up your Atom’s styles.less file, which is under the “Atom” menu option:

打开您的Atom的styles.less文件,该文件位于“ Atom”菜单选项下:

Write the following lines of code into Atom’s styles.less file:

将以下代码行写入Atom的styles.less文件中:

atom-text-editor::shadow { .git-commit.invalid.deprecated.line-too-long {  color: @text-color-warning;  text-decoration: none; }
.git-commit.invalid.illegal.line-too-long {  color: @text-color-selected;  background: @background-color-error;  opacity: 0.9; }}

Once you’ve made the changes and saved the file, Atom will behave as shown in Figure 2.

进行更改并保存文件后,Atom的行为将如图2所示。

编写用于提交消息结构的代码段 (Write a snippet for commit message structure)

Second, we will write a short snippet for commit messages. This snippet will provide placeholders for subject line and body that can be navigated using TAB key.

其次,我们将为提交消息编写一个简短的代码段。 此摘要将提供主题行和正文的占位符,可以使用TAB键进行导航。

Write the following lines of code into Atom’s snippets.cson:

将以下代码行写入Atom的snippets.cson:

'.text.git-commit':  'commit-message':    'prefix': 'comm'    'body': """      ${1:Subject < 50 chars}
${2:Body in detail}    """

After you make the changes and save the snippets file, the next time you open your commit message, you just need to type comm and press TAB to expand your snippet.

进行更改并保存摘录文件后,下次打开提交消息时,只需键入comm并按TAB键即可扩展摘录。

Once the snippet has been expanded, you can press TAB again to jump the cursor from ‘subject line’ to ‘body’. Figure 3 shows this snippet in action.

扩展代码段后,您可以再次按TAB键将光标从“主题行”跳转到“正文”。 图3显示了该片段的运行情况。

These little code snippets have sure improved my git commit workflow, and I’m confident they can improve yours.

这些小代码段确实改善了我的git commit工作流程,并且我相信它们可以改善您的git commit工作流程。

If you have any other committing-related snippets that you use in Atom, please be sure to post them. I’d love to have a look and maybe incorporate them into my workflow.

如果您在Atom中使用其他任何与提交相关的摘要,请确保将其发布。 我很想看看,也许可以将它们合并到我的工作流程中。

Also — for those curious — here’s a list of themes and packages I’ve used in the above figures:

另外-对于那些好奇的人-这是我在上图中使用的主题和包的列表:

翻译自: https://www.freecodecamp.org/news/towards-better-git-commit-messages-using-atom-6dbda5e14984/

atom 中首次使用git

 类似资料: