首页 > 其他分享 >Git commit - Angular Convention

Git commit - Angular Convention

时间:2023-09-11 23:56:10浏览次数:43  
标签:body Git angular 提交 Commit commit message Angular

使用 Git 的开发者会使用 git commit 进行代码提交,也会使用 -m 提交commit message。对于一些个人开发者,也许他们会觉得“这是我个人的项目,不用太在意git commit message 的格式或者规范”。

但是对于一个团队或者在开源项目上工作的话,对于 commit message 的质量就会有比较高的要求了。一个好的 Git commit message 是向项目的其他参与者进行提交信息说明的十分重要的途径,对于开发这个人而言也在未来回顾提交信息的时候十分有意义。

有时候我们在旧项目上使用 git log 的时候会发现一堆杂乱的 commit messages。很难读懂当时提交这条 commit 的原因,增加或者修改了哪些内容。所以,一个“好”的 commit message 的重要性在于:

  • 一些项目需要严谨的开发过程,以及清楚的可追溯性,相关的责任人。 当这些项目出现问题时,重要的是要知道确切的原因:哪些代码更改不正确,哪些用户会受此问题影响,为什么当时修改了代码等等。
  • 好的代码值得被“认真”地分享。开发者应该不希望自己辛苦写了一个礼拜的代码提交为“add some new features”。我觉得这是对于开发者自己劳动成果的一种不尊重,至少需要体现出解决了哪些问题,哪里比较“酷”。

所以为了其他人,也为了自己,请认真对待 commit messages :)

参考下面的 commit (来自网络):

e5f4b49 Re-adding ConfigurationPostProcessorTests after its brief removal in r814. @Ignore-ing the testCglibClassesAreLoadedJustInTimeForEnhancement() method as it turns out this was one of the culprits in the recent build breakage. The classloader hacking causes subtle downstream effects, breaking unrelated tests. The test method is still useful, but should only be run on a manual basis to ensure CGLIB is not prematurely classloaded, and should not be run as part of the automated build.
2db0f12 fixed two build-breaking issues: + reverted ClassMetadataReadingVisitor to revision 794 + eliminated ConfigurationPostProcessorTests until further investigation determines why it causes downstream tests to fail (such as the seemingly unrelated ClassPathXmlApplicationContextTests)
147709f Tweaks to package-info.java files
22b25e0 Consolidated Util and MutableAnnotationUtils classes into existing AsmUtils
7f96f57 polishing

每次提交的内容从长度到格式都不同,写法像是“意识流”(非褒义)。在 github 上很多项目都是类似的提交格式,但是也有比较清晰准确的 commit messages,比如 Linux kernel,读者可以参考。

开发者可以自己制定一套 commit 的格式,也可以使用流行的一些格式。这里想要分享的是我个人和团队在使用的一种 commit convention: Angular。

https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines​github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines

概述

Angular 规定 commit message 的结构如下:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

header + body(可选) + footer(可选)

header

header 包含三部分:type + scope + subject。比如,

feat(lang): add polish language

(1)type

  • feat:新功能(feature)
  • fix:修补bug
  • docs:文档(documentation)
  • style: 格式(不影响代码运行的变动)
  • refactor:重构(即不是新增功能,也不是修改bug的代码变动)
  • test:增加测试
  • chore:构建过程或辅助工具的变动

在 type 后面增加“!”代表重大的代码更改。

(2)scope

用于说明 commit 影响的范围,比如数据层、控制层、或者项目名称等等。

(3)subject

commit 的简短描述,不超过50个字符。

  • 以动词开头,使用第一人称现在时,比如change,而不是changedchanges
  • 第一个字母小写
  • 结尾不加句号(.

body (非必须)

body 是详细描述的信息,例如:

More detailed explanatory text, if necessary.  Wrap it to 
about 72 characters or so. 

Further paragraphs come after blank lines.

- Bullet points are okay, too
- Use a hanging indent

footer (非必须)

(1)不兼容变动

如果当前代码与上一个版本不兼容,则 Footer 部分以BREAKING CHANGE开头,后面是对变动的描述、以及变动理由和迁移方法。

(2)关闭 Issue

如果当前 commit 针对某个issue,那么可以在 Footer 部分关闭这个 issue 。

Closes #234

示例

Commit message with description and breaking change footer

feat: allow provided config object to extend other configs

BREAKING CHANGE: `extends` key in config file is now used for extending other config files

Commit message with ! to draw attention to breaking change

refactor!: drop support for Node 6

Commit message with both ! and BREAKING CHANGE footer

refactor!: drop support for Node 6

BREAKING CHANGE: refactor to use JavaScript features not available in Node 6.

Commit message with no body

docs: correct spelling of CHANGELOG

Commit message with scope

feat(lang): add polish language

Commit message with multi-paragraph body and multiple footers

fix: correct minor typos in code

see the issue for details

on typos fixed.

Reviewed-by: Z
Refs #133

参考

https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines

https://www.conventionalcommits.org/en/v1.0.0/

https://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html

发布于 2020-12-24 10:27

标签:body,Git,angular,提交,Commit,commit,message,Angular
From: https://www.cnblogs.com/exmyth/p/17694909.html

相关文章

  • 如何将GitLab仓库同步到GitHub和Gitee?
    作者:西瓜程序猿主页传送门:https://blog.51cto.com/kimiliucn前言在之前写的【Kimi.RocketMQ.NET】开源项目中,代码我是放在自己搭建的GitLab服务器上,然后我每次提交的代码希望实时同步到GitHub和Gitee上,那所以这篇文章来记录一下GitLab如何同步到GitHub,GitLab如何同步到Gitee。当然......
  • 使用Github Action在Github Pages上部署vue页面
    GithubAction部分:name:NodeJSon:push:branches:["master"]#SetspermissionsoftheGITHUB_TOKENtoallowdeploymenttoGitHubPagespermissions:contents:write#Allowonlyoneconcurrentdeployment,skippingrunsqueuedbetwee......
  • PostgreSQL数据库从入门到精通系列之五:深入理解lsn_proc、lsn_commit、lsn、txId、ts_
    PostgreSQL数据库从入门到精通系列之五:深入理解lsn_proc、lsn_commit、lsn、txId、ts_usec一、深入理解lsn_proc二、深入理解lsn_commit三、深入理解lsn四、深入理解txId五、深入理解ts_usec一、深入理解lsn_proc在PostgreSQL中,lsn_proc是一个内置函数,用于将逻辑日志位置(LSN)转换......
  • git 基本操作
    1、第一次初始化gitinitgitadd.gitcommit-m‘firstcommit’[email protected]:帐号名/仓库名.gitgitpulloriginmastergitpushoriginmaster#-f强推[email protected]:git帐号名/仓库名.git2、工作基本操作gitcheckoutmast......
  • Git:分布式版本控制系统的利器
    在现代软件开发中,版本控制是一个至关重要的环节。Git作为一款分布式版本控制系统,为开发者们提供了高效、灵活的版本管理方案。本文将介绍Git的基本用法和主要特点,帮助您更好地理解和使用这个强大的工具。Git简介Git是由LinusTorvalds创造的分布式版本控制系统,以其速度和灵活性而闻......
  • 将git的本地仓库提交到远程仓库
    #先初始化本地仓库gitinit#将所有文件添加到缓存gitadd.#将缓存文件提交给git仓库,在执行这句时,会让填写提交的介绍信息,这里和linux的vim编辑器类型gitcommit#与远程仓库建立连接,(gitremoteaddorigin+远程仓库地址)gitremoteaddoriginhttps://gitee.com/......
  • git 本地master分支合并其他分支
    一、切换到主分支gitcheckoutmaster二、主分支合并其他分支gitmergeyf_dev三、切换到其他分支gitcheckoutyf_dev四、推送到远程分支gitpush-uoriginyf_dev......
  • 使用Gitee极速下载Nacos项目制作windows启动
    步骤一使用国内链接下载nacos项目:https://gitee.com/mirrors/Nacos 步骤二进入下载好的nacos主目录下执行maven打包命令,在此之前需要配置好Maven mvn-Prelease-nacos-Dmaven.test.skip=truecleaninstall-U 打包成功的结果图步骤三打包好的启动项存在:E:\Nacos......
  • git 常用命令
    查看修改的状态(status)gitstatus添加工作区到暂存区(add)gitadd提交暂存区到本地仓库(commit)gitcommit查看提交日志(log)gitlog--all显示所有分支--pretty=oneline将提交信息显示为一行--abbrev-commit使得输出的commitId更简短--graph以图的形式显示版本......
  • shell 执行git 拉取代码并运行jar包
    #!/bin/shecho“正在获取git最新代码,请输入正确的用户名与密码”output=gitpulloriginmastera=$?b=0if[$a=$b];thenecho“代码拉取成功,正在执行打包”mvnclean&&mvncompile&&mvninstallecho“jar包复制到/mydata/app”mv-f/mydata/idg-server/target/a.jar......