git 原理详解及实用指南

To create a useful revision history, teams should first agree on a commit message convention to use. This also applies to personal projects.

要创建有用的修订历史记录,团队应该首先同意要使用的提交消息约定。 这也适用于个人项目。

Recently on Hashnode I asked, "Which commit message convention do you use at work?" and I got some amazing responses with users explaining the conventions they use at work and for their personal projects.

最近在Hashnode上,我问: “您在工作中使用哪种提交消息约定?” 我收到了一些用户的好评,解释了他们在工作中和用于个人项目时所使用的约定。

In this article, I'll go over how to write good commit messages and why you should.

在本文中,我将介绍如何编写良好的提交消息以及为什么要这样做。

PS:本文首次发表在我的博客在这里 。 (PS: This article was first published on my blog here.)

Git版本控制简介 (Introduction to version control with Git)

Version control software is an essential part of modern-day software developer practices.

版本控制软件是现代软件开发人员实践的重要组成部分。

By far, Git is the most widely used version control system in the world. It is a distributed and actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.

到目前为止, Git是世界上使用最广泛的版本控制系统。 它是一个分布式且积极维护的开源项目,最初由Linux操作系统内核的著名创建者Linus Torvalds于2005年开发。

New to Git? Check out the official getting started guide or this slide from a past talk I gave.

刚接触Git? 请查看官方的入门指南或我以前的演讲中的这张幻灯片 。

什么是提交消息? (What is a commit message?)

The commit command is used to save changes to a local repository after staging in Git. However, before you can save changes in Git, you have to tell Git which changes you want to save as you might have made tons of edits. A great way to do that is by adding a commit message to identify your changes.

在Git中暂存后,使用commit命令将更改保存到本地存储库。 但是,在Git中保存更改之前,您必须告诉Git您要保存哪些更改,因为您可能已经进行了大量的编辑。 做到这一点的一种好方法是添加一个提交消息以标识您的更改。

提交选项 (Commit Options)

  • -m

    -米

This option sets the commit's message.

此选项设置提交的消息。

git add static/admin/config.yml
git commit -m "Setup multiple roles for netlify-cms git gateway"
  • -a or --all

    -a或--all

This option automatically commits all (including new) tracked, modified or deleted files.

此选项自动提交所有(包括新的)跟踪,修改或删除的文件。

git commit -a -m "Add a new role for netlify-cms git gateway"
  • --amend

    - 修改

This option rewrites the very last commit with any currently staged changes or a new commit message and should only be performed on commits that have not been pushed to a remote repository, yet.

此选项将使用任何当前暂存的更改或新的提交消息重写最后的提交,并且应仅对尚未推送到远程存储库的提交执行此操作。

git add .
git commit --amend -m "Update roles for netlify-cms git gateway"

为什么要编写良好的提交消息? (Why should you write good commit messages?)

You might say, "It's just a personal project." Yes, you work alone now, but what happens when you work with a team or contribute to open source?

您可能会说:“这只是一个个人项目。” 是的,您现在一个人工作,但是当您与团队一起工作或为开源做出贡献时会怎样?

A well-crafted Git commit message is the best way to communicate context about a change to other developers working on that project, and indeed, to your future self.

精心设计的Git提交消息是与正在进行该项目的其他开发人员以及您未来的自我交流有关更改的上下文的最佳方法。

Have you ever tried running git log on one of your old projects to see the "weird" commit messages you have used since its inception? It can be hard to understand why you made some changes in the past, and you'll wish you read this article earlier :).

您是否曾经尝试在您的一个旧项目上运行git log来查看自创建以来使用的“怪异”提交消息? 很难理解为什么您过去进行了一些更改,并且希望您早些阅读本文:)。

Commit messages can adequately communicate why a change was made, and understanding that makes development and collaboration more efficient.

提交消息可以充分传达进行更改的原因,以及可以使开发和协作更加有效的理解。

如何使用Git编写提交消息 (How to write commit messages with Git)

Before now, I only used git commit -m "Fix X to allow Y to use Z" on my personal projects with just a subject and no extra description. This is great for small and clear fixes like git commit -m "Fix typo in README.md, but in cases of more extensive changes, you would need to add some extra details.

在此之前,我只在个人项目上使用了git commit -m "Fix X to allow Y to use Z" ,并且仅提供了一个主题,没有附加描述。 这对于小而清晰的修复非常git commit -m "Fix typo in README.md ,例如git commit -m "Fix typo in README.md ,但是在更广泛的更改的情况下,您需要添加一些额外的细节。

编辑器方法 (Editor method)

Run git commit without a message or option and it'll open up your default text editor to write a commit message.

运行没有消息或选项的git commit ,它将打开您的默认文本编辑器以编写提交消息。

To configure your "default" editor:

配置“默认”编辑器:

git config --global core.editor nano

This would configure Git to use nano as your default editor. Replace "nano" with "emacs," "vim," or whatever your preference is.

这会将Git配置为使用nano作为默认编辑器。 用“ emacs”,“ vim”或任何您喜欢的名称替换“ nano”。

In the opened editor, the first line is the subject (short description), leave a blank line after it, and everything else is the extended description (body).

在打开的编辑器中,第一行是主题(简短描述),其后留空行,其他所有内容都是扩展描述(正文)。

<Summarize change(s) in around 50 characters or less><More detailed explanatory description of the change wrapped into about 72
characters>

命令行方式 (Command Line method)

git commit -m "Subject" -m "Description..."

The first -m option is the subject (short description), and the next is the extended description (body).

第一个-m选项是主题(简短描述),第二个是扩展描述(正文)。

如何编写良好的提交消息 (How to write good commit messages)

There are several conventions used by different teams and developers to write good commit messages. I'll only outline some general rules and tips for writing commit messages–you have to decide what convention you want to follow. And if you work for a company or contribute to open source, you have to adapt to their convention :).

不同的团队和开发人员使用几种约定来编写良好的提交消息。 我将仅概述一些用于编写提交消息的一般规则和技巧-您必须确定要遵循的约定。 而且,如果您在公司工作或为开源做贡献,则必须适应他们的惯例:)。

For consistency, you can use one convention for work and another for personal projects as you might change jobs sometime, and the convention might also change.

为了保持一致性,您可以在工作中使用一种约定,而在个人项目中使用另一种约定,因为您有时可能会更改工作,并且约定也可能会更改。

Be sure to check out this thread for some amazing commit message conventions or add yours to help someone make a decision.

一定要签出该线程以了解一些惊人的提交消息约定,或者添加您的约定以帮助某人做出决定。

Here's a great template of a good commit message originally written by Tim pope

这是Tim Pope最初编写的良好提交消息的一个很好的模板

Capitalized, short (50 chars or less) summaryMore detailed explanatory text, if necessary.  Wrap it to about 72
characters or so.  In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body.  The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
or "Fixes bug."  This convention matches up with commit messages generated
by commands like git merge and git revert.Further paragraphs come after blank lines.- Bullet points are okay, too- Typically a hyphen or asterisk is used for the bullet, followed by asingle space, with blank lines in between, but conventions vary here- Use a hanging indentIf you use an issue tracker, add a reference(s) to them at the bottom,
like so:Resolves: #123

Looks great, right? Here's how you can make yours great too:

看起来不错吧? 您也可以通过以下方法使自己的实力变得出色:

  1. Specify the type of commit:指定提交的类型:
  • feat: The new feature you're adding to a particular application壮举:您要添加到特定应用程序的新功能
  • fix: A bug fix修复:一个错误修复
  • style: Feature and updates related to styling样式:与样式相关的功能和更新
  • refactor: Refactoring a specific section of the codebase重构:重构代码库的特定部分
  • test: Everything related to testing测试:与测试相关的所有内容
  • docs: Everything related to documentationdocs:与文档相关的所有内容
  • chore: Regular code maintenance.[ You can also use emojis to represent commit types]杂务:常规代码维护。[您也可以使用表情符号来表示提交类型]
  1. Separate the subject from the body with a blank line用空白行将主体与身体分开
  2. Your commit message should not contain any whitespace errors您的提交消息不应包含任何空格错误
  3. Remove unnecessary punctuation marks删除不必要的标点符号
  4. Do not end the subject line with a period主题行不要以句号结尾
  5. Capitalize the subject line and each paragraph大写主题行和每个段落
  6. Use the imperative mood in the subject line在主题行中使用命令式心情
  7. Use the body to explain what changes you have made and why you made them.用正文解释您进行了哪些更改以及为什么进行更改。
  8. Do not assume the reviewer understands what the original problem was, ensure you add it.不要假定审阅者了解原始问题是什么,请确保将其添加。
  9. Do not think your code is self-explanatory不要以为您的代码是不言自明的
  10. Follow the commit convention defined by your team遵循团队定义的提交约定

结论 (Conclusion)

The most important part of a commit message is that it should be clear and meaningful. In the long run, writing good commit messages shows how much of a collaborator you are. The benefits of writing good commit messages are not only limited to your team, but indeed expand to yourself and future contributors.

提交消息最​​重要的部分是它应该清晰而有意义。 从长远来看,编写良好的提交消息可以表明您有多少协作者。 编写良好的提交消息的好处不仅限于您的团队,而且的确扩展到您自己和将来的贡献者。

Want to learn more about Git and become a professional "version controller"? Check out these excellent resources:

想更多地了解Git并成为专业的“版本控制器”吗? 查看以下优秀资源:

  • https://try.github.io/

    https://try.github.io/

  • https://git-scm.com/book/en/v2

    https://git-scm.com/book/zh/v2

  • https://www.git-tower.com/learn/

    https://www.git-tower.com/learn/

  • https://learngitbranching.js.org/

    https://learngitbranching.js.org/

  • https://github.com/commitizen/cz-cli

    https://github.com/commitizen/cz-cli

翻译自: https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/

git 原理详解及实用指南

git 原理详解及实用指南_如何编写良好的提交消息:实用的Git指南相关推荐

  1. Git 原理详解及实用指南

    Git 原理详解及实用指南 什么是版本控制系统(VCS) 很多人认为 Git 难以理解的第一个门槛在于:所谓的「Git 是一个分布式版本控制系统」这句话的具体含义不够清楚.其实分布式版本控制系统(Di ...

  2. git原理详解与实操指南_全网最精:学git一套就够了,从入门到原理深度剖析

    以上资源收集至互联网 如有侵权请联系删除 资源获取方式 扫码关注资源库公众号 回复密码'20190812' 即可获得 截图展示 课程信息 课程难度:中级 学习人数:148352 课程状态:已完结 时长 ...

  3. 一天彻底搞懂 Git 《Git 原理详解及实用指南》

    我是扔物线,Android 开发者,开源贡献者,在 GitHub 上有 4.9k followers 和 7.8k stars ,个人的 Android 开源库 MaterialEditText 被全 ...

  4. Git原理详解与实用指南

    文章目录 上手 1:新公司用 Git 管理代码,怎么快速上手? 上手2:团队工作的基本工作模型 进阶1:HEAD.master与branch 进阶2:push的本质 进阶3:merge:合并commi ...

  5. python使用kafka原理详解真实完整版_史上最详细Kafka原理总结

    Kafka Kafka是最初由Linkedin公司开发,是一个分布式.支持分区的(partition).多副本的(replica),基于zookeeper协调的分布式消息系统,它的最大的特性就是可以实 ...

  6. git原理详解与实操指南_基于dockercompose的Gitlab CI/CD实践amp;排坑指南

    长话短说 经过长时间实操验证,终于完成基于Gitlab的CI/CD实践,本次实践的坑位很多, 实操过程尽量接近最佳实践(不做hack, 不做骚操作),记录下来加深理解. 看过博客园<docker ...

  7. python使用kafka原理详解真实完整版_转:Kafka史上最详细原理总结 ----看完绝对不后悔...

    消息队列的性能好坏,其文件存储机制设计是衡量一个消息队列服务技术水平和最关键指标之一.下面将从Kafka文件存储机制和物理结构角度,分析Kafka是如何实现高效文件存储,及实际应用效果. 1.1  K ...

  8. FPGA——用VGA时序显示图像原理详解(2)

    目录 VGA时序 VGA显示 大家结合上一篇: FPGA--用VGA时序显示图像原理详解(1)_居安士的博客-CSDN博客 VGA时序 首先我们下载数据手册,我们可以根据自己的需求,选择图像大小,以及 ...

  9. Git的原理详解与使用-臧雪园-专题视频课程

    Git的原理详解与使用-3人已学习 课程介绍         2018 Git的原理详解与使用视频教程,该课程主要从四个部分进行讲解:第一部分主要讲解了Git的基本使用.比如安装和git基本命令使用, ...

最新文章

  1. JS模块化工具requirejs教程02
  2. 单张图像就可以训练GAN!Adobe改良图像生成方法 | 已开源
  3. Arria10_emif
  4. MVC RC2中关于HtmlHelper给DropDownList设置初始选中值的问题
  5. 区块链是大数据生态圈技术之一_区块链技术再发力,携手智能制造构建产业生态圈...
  6. PDT + Xdebug 调试 PHP
  7. nginx应用总结(1)--基础认识和应用配置
  8. clickhouse 副本ReplicateMergeTree实现原理
  9. 用matlab做bp神经网络预测,神经网络预测matlab代码
  10. OpenStack温哥华峰会Day2日记:大数据带你看峰会热点
  11. php遍历桌面上的记事本,电脑桌面显示记事本便签内容要怎么设置一直锁定在桌面?...
  12. 刷题——逆波兰表达式
  13. docker安装文档(多种方式)
  14. 61_ZYNQ7020开发板_SD/QSPI方式启动_ax_peta
  15. 计算机网络技术在实践中应用,计算机网络技术及在实践中的具体应用
  16. ERROR: pip‘s dependency resolver does not currently take into account all the packages that are inst
  17. PAT 1044 火星数字
  18. Pytorch 学习日记(一)
  19. Python.win32gui.获取窗体
  20. 双硬盘装双系统遇到的坑

热门文章

  1. 字节流读数据 一次读一个字节
  2. html盒子模型 1209
  3. 数据结构与算法-没有算法的操作VS有算法的操作,性能大提升
  4. linux-新建一个centos虚拟机系统-安装全过程图示
  5. SQL Server查询锁等待
  6. https://www.cnblogs.com/jingmoxukong/p/7755643.html
  7. 《纲要》落地,东方通教你挖数据金矿
  8. 【51CTO学院三周年】学业有成啦
  9. JQuery文件上传控件Uploadify文档
  10. 虚拟化系列-VMware vSphere 5.1 虚拟机管理