git 撤销变更_Git入门指南—什么是变更日志以及如何生成变更日志

git 撤销变更

Say you are a developer, and you use Git for one of your projects. You want to share the changes you made with your users, but you don’t know how. Well, then this article is for you.

假设您是一名开发人员,并且将Git用于其中一个项目。 您想与用户共享所做的更改,但是您不知道如何做。 好,那么这篇文章适合您。

In the last part of this series, I shared with you how to write a good commit message.

在本系列的最后一部分中,我与您分享了如何编写良好的提交消息

I gave you an overview of the benefits of writing a good commit, and I mentioned the possibility of generating a changelog.

我概述了编写良好提交的好处,并提到了生成变更日志的可能性。

In this article, you will learn what a changelog is along with two ways to generate it – a simple one and a sophisticated one.

在本文中,您将了解什么是变更日志以及两种生成方式-简单的方式和复杂的方式。

什么是变更日志? (What is a changelog?)

A changelog is a file that shares a chronologically ordered list of the changes you've made on your project. It’s often organized by the version with the date followed by a list of added, improved, and removed features.

变更日志是一个文件,它按时间顺序共享您对项目所做的更改。 它通常按版本进行组织,并带有日期,其后是添加,改进和删除的功能的列表。

Globally, there are two ways to write a changelog:

在全球范围内,有两种编写变更日志的方法:

  • the usual way: create a text file and start to enumerate all your changes with a specific date

    通常的方法:创建一个文本文件,并开始枚举所有具有特定日期的更改
  • the developer choice (alias the lazy option): auto-generate your changelog from your commit messages. I have good news for you – this is what you’re going to learn in this article!

    开发人员的选择(别名为lazy选项):根据提交消息自动生成变更日志。 我对您有个好消息-这就是您将在本文中学习的内容!

“A changelog is a log or record of all notable changes made to a project. The project is often a website or software project, and the changelog usually includes records of changes such as bug fixes, new features, etc.” – Wikipedia

“变更日志是对项目进行的所有显着变更的日志或记录。 该项目通常是一个网站或软件项目,并且更改日志通常包括更改记录,例如错误修复,新功能等。” – 维基百科

为什么必不可少? (Why is it essential?)

I think, even now, you are asking yourself why it is essential and why you should take the time to create it.

我认为,即使是现在,您仍在问自己为什么它至关重要,为什么要花时间创建它。

A changelog is a kind of summary of all your changes. It should be easy to understand both by the users using your project and the developers working on it.

变更日志是所有变更的摘要。 使用项目的用户和从事该项目的开发人员都应该易于理解。

In a world where everything is evolving quickly, a user needs to know if the website/software they are using is changing. You might be surprised, but people love to read blog posts or an update page on your website.

在一切都在快速发展的世界中,用户需要知道他们使用的网站/软件是否正在更改。 您可能会感到惊讶,但是人们喜欢阅读您网站上的博客文章或更新页面。

For a developer, for example, if the project is big, it can be interesting to know how the software they're working on is evolving.

例如,对于开发人员来说,如果项目很大,那么了解他们正在开发的软件是如何发展的就可能很有趣。

Or if you are working on an open-source project, you can find a "CHANGELOG.md" file in the GitHub repository. This file aims to inform contributors of the latest updates on the project.

或者,如果您正在开发一个开源项目,则可以在GitHub存储库中找到一个“ CHANGELOG.md”文件。 该文件旨在将项目的最新更新告知贡献者。

我们在哪里找到它们? (Where do we find them?)

Changelogs are everywhere! Okay, they often have different styles and locations, but they're literally on every project.

变更日志无处不在! 好的,它们通常具有不同的样式和位置,但实际上它们存在于每个项目中。

I created a short list with a few places where you can find a changelog.

我创建了一个简短列表,列出了一些可以找到变更日志的地方。

  • A blog post. A changelog can be delivered under an article sharing the last features point by point.

    博客文章。 可以在逐点共享最后功能的文章下提供更改日志。
  • A "CHANGELOG.md" file in a GitHub repository.

    GitHub存储库中的“ CHANGELOG.md”文件。
  • A Changelog section on your favourite website/software. Here's one example with the task management tool TickTick.

    您喜欢的网站/软件上的Changelog部分。 这是任务管理工具TickTick一个示例

  • In "What's new" on the Android and the IOS store.

    在Android和IOS商店的“新功能”中。

Changelog自动生成 (Changelog auto-generation )

In this part, we're going to generate our first changelog together.

在这一部分中,我们将一起生成我们的第一个变更日志。

By doing this task, you will understand why it can be useful to commit by following some rules.

通过执行此任务,您将了解为什么遵循某些规则进行提交可能很有用。

An excellent and explicit commit doesn't need to be modified and can be directly added to the changelog.

优秀且明确的提交无需修改,可以直接添加到变更日志中。

If you are interested in generating a necessary file without any personalisation or beautification, I recommend the first way; otherwise, the second one is better.

如果您有兴趣在不进行任何个性化或美化的情况下生成必要的文件,建议您采用第一种方法; 否则,第二个更好。

Note: Some websites such as Keep A Changelog explain that you shouldn't make a changelog only by copying and pasting your git commits (refer to the simple way). Indeed, I recommend trying to avoid this way if you are working on a professional product.

注意 :一些网站,例如Keep A Changelog解释说,您不应该仅通过复制和粘贴git提交来制作更改日志(请参考简单方法)。 确实,如果您正在开发专业产品,我建议尝试避免这种方式。

However, nowadays, there are some advanced generators that allow you to change your git logs into changelogs (refer to the sophisticated way).

但是,如今,有一些高级生成器可让您将git日志更改为changelog(请参阅复杂的方法)。

如何生成变更日志(简单方法) (How to generate a changelog (the simple way))

By using this first way, you don't need any prerequisites. All you need is to type a few commands inside your Git repository.

通过使用第一种方法,您不需要任何先决条件。 您只需要在Git存储库中键入一些命令即可。

As a simple reminder, when you type "git log", a list of all your commits is displayed.

作为简单的提醒,当您键入“ git log”时,将显示所有提交的列表。

$ git log

// Output
commit f6986f8e52c1f889c8649ec75c5abac003102999 (HEAD -> master, origin/master, origin/HEAD)
Author: Sam Katakouzinos <sam.katakouzinos@gmail.com>
Date:   Tue Mar 10 11:41:18 2020 +1100

    docs(developers): commit message format typo
    
    Any line of the commit message cannot be longer *than* 100 characters!
    
    Closes #17006

commit ff963de73ab8913bce27a1e75ac01f53e8ece1d9
Author: Chives <chivesrs@gmail.com>
Date:   Thu Feb 6 19:05:57 2020 -0500

    docs($aria): get the docs working for the service
    
    Closes #16945

commit 2b28c540ad7ebf4a9c3a6f108a9cb5b673d3712d
Author: comet <hjung524@gmail.com>
Date:   Mon Jan 27 19:49:55 2020 -0600

    docs(*): fix spelling errors
    
    Closes #16942

This command can take a few parameters. We are going to use them to change the output and get an improved one to generate our changelog.

该命令可以使用一些参数。 我们将使用它们来更改输出并获得改进的输出以生成我们的更改日志。

By typing the following command, you will have an output with one commit per line.

通过键入以下命令,您将获得每行提交一次的输出。

$ git log --oneline --decorate

// Output
f6986f8e5 (HEAD -> master, origin/master, origin/HEAD) docs(developers): commit message format typo
ff963de73 docs($aria): get the docs working for the service
2b28c540a docs(*): fix spelling errors
68701efb9 chore(*): fix serving of URI-encoded files on code.angularjs.org
c8a6e8450 chore(package): fix scripts for latest Node 10.x on Windows
0cd592f49 docs(angular.errorHandlingConfig): fix typo (wether --> whether)
a4daf1f76 docs(angular.copy): fix `getter`/`setter` formatting
be6a6d80e chore(*): update copyright year to 2020
36f17c926 docs: add mention to changelog
ff5f782b2 docs: add mention to changelog
27460db1d docs: release notes for 1.7.9
add78e620 fix(angular.merge): do not merge __proto__ property

It’s better, but let’s see what we can do with the following one.

更好,但是让我们看看如何使用以下方法。

$ git log --pretty=”%s”

// Output
docs(developers): commit message format typo
docs($aria): get the docs working for the service
docs(*): fix spelling errors
chore(*): fix serving of URI-encoded files on code.angularjs.org
chore(package): fix scripts for latest Node 10.x on Windows
docs(angular.errorHandlingConfig): fix typo (wether --> whether)
docs(angular.copy): fix `getter`/`setter` formatting
chore(*): update copyright year to 2020
docs: add mention to changelog
docs: add mention to changelog
docs: release notes for 1.7.9
fix(angular.merge): do not merge __proto__ property

With this one, you can print the list of commits with the style you want.

通过这一步,您可以使用所需样式打印提交列表。

The “%s” corresponds to the commit title itself. You can modify the string to style your commit as you like.

“%s”对应于提交标题本身。 您可以修改字符串以根据需要设置提交样式。

In our case, we want to create a list.

在我们的情况下,我们要创建一个列表。

$ git log --pretty="- %s"

// Output
- docs(developers): commit message format typo
- docs($aria): get the docs working for the service
- docs(*): fix spelling errors
- chore(*): fix serving of URI-encoded files on code.angularjs.org
- chore(package): fix scripts for latest Node 10.x on Windows
- docs(angular.errorHandlingConfig): fix typo (wether --> whether)
- docs(angular.copy): fix `getter`/`setter` formatting
- chore(*): update copyright year to 2020
- docs: add mention to changelog
- docs: add mention to changelog
- docs: release notes for 1.7.9
- fix(angular.merge): do not merge __proto__ property

You did it! You created a simple changelog.

你做到了! 您创建了一个简单的变更日志。

Note: If you want to go further, and save your changelog faster: instead of copying and pasting the result into a file, redirect it to your terminal by typing “git log --pretty="- %s" > CHANGELOG.md”

注意 :如果您想走得更远,并更快地保存您的变更日志:而不是将结果复制并粘贴到文件中,而是通过输入“ git log --pretty =“-%s”> CHANGELOG.md”将其重定向到您的终端

如何生成变更日志(复杂方式) (How to generate a changelog (the sophisticated way))

Prerequisites

先决条件

We are now going to explore a sophisticated way to generate a changelog. The idea behind the process stays the same, but this time we’re going to use other tools to help us.

现在,我们将探索一种复杂的方式来生成变更日志。 流程背后的想法保持不变,但是这次我们将使用其他工具来帮助我们。

Do you remember when in the last part of this series I wrote about the Git guidelines?

您还记得我在本系列的最后一部分中写过有关Git准则的内容吗?

Note: Git guidelines are a set of rules to write your commits better. These guidelines help you add some structure to your commits.

注意 :Git准则是一组规则,可以更好地编写提交。 这些准则可帮助您为提交添加一些结构。

When you are using a guideline for your project, you can use tools to generate a changelog. Most of the time, these tools are better because they allow you to create a markdown formatted changelog.

在为项目使用准则时,可以使用工具来生成变更日志。 在大多数情况下,这些工具会更好,因为它们使您可以创建降价格式的变更日志。

In this example, we’re going to use a simple generator which works with most of the guidelines. Its name is “generate-changelog”, and it’s available on NPM (the Node Package Manager).

在此示例中,我们将使用一个简单的生成器,该生成器可与大多数准则配合使用。 它的名称为“ generate-changelog ”,在NPM(节点程序包管理器)上可用。

This tool is going to create a stylised changelog, but it’s not the one with the most features. I decided to use it because it’s an excellent example for a beginner. If you want to go further, please refer to the list of changelog tools below:

该工具将创建一个风格化的变更日志,但并不是功能最多的工具。 我决定使用它,因为它是初学者的绝佳范例。 如果您想走得更远,请参考下面的变更日志工具列表:

Here are a few tools you can use:

您可以使用以下几种工具:

Note: Before installing the tool, you need to have NPM installed on your computer. If you don't have it, I invite you to follow the official website (it will help you to install Node and NPM).

注意:在安装该工具之前,您需要在计算机上安装NPM。 如果没有,我邀请您访问官方网站 (它将帮助您安装Node和NPM)。

To install the package on your computer, type the following command in your terminal.

要在计算机上安装软件包,请在终端中键入以下命令。

$ npm install generate-changelog -g

Once you do that, it’s installed!

完成后,就可以安装了!

How to use it

如何使用它

To make this package work, you need to follow the guidelines for using this pattern – “type(category): description [flags]”. In this example, I will use the Angular.js GitHub repository.

要使此程序包正常工作,您需要遵循使用此模式的准则-“类型(类别):description [flags]”。 在此示例中,我将使用Angular.js GitHub存储库。

Now you can type the generate command in your terminal inside your GitHub repository.

现在,您可以在GitHub存储库中的终端中键入generate命令。

$ changelog generate

A “CHANGELOG.md” file will be automatically created and filled with your logs in a markdown format.

将自动创建一个“ CHANGELOG.md”文件,并以降价格式填充您的日志。

You can find an example of the output (with a markdown reader such as GitHub) below.

您可以在下面找到输出示例(带有markdown阅读器,例如GitHub)。

结论 (Conclusion)

I hope you liked this guide and now understand how to create a changelog for your project. I think it’s a good way to demonstrate why you should write good commit messages.

希望您喜欢本指南,并且现在了解如何为您的项目创建变更日志。 我认为这是演示为什么要编写良好的提交消息的好方法。

Feel free to try other changelog generators and send me the result!

随时尝试其他changelog生成器,并将结果发送给我!

If you have any questions or feedback, please let me know.

如果您有任何疑问或反馈,请告诉我。

Don't miss my content by following me on Twitter and Instagram.

TwitterInstagram上关注我,不要错过我的内容。

You can find other articles like this on my website: herewecode.io.

您可以在我的网站上找到其他类似的文章: herewecode.io

想要更多? (Want more?)

  • Each week get a motivational quote with some advice, a short tutorial in a few slides, and one developer's picture on Instagram.

    每周都会收到一些激励性的报价,其中包含一些建议,一些幻灯片中的简短教程以及Instagram上一张开发人员的照片。

  • Sign-up for the newsletter and get the latest articles, courses, tutorials, tips, books, motivation, and other exclusive content.

    注册时事通讯并获取最新文章,课程,教程,技巧,书籍,动机和其他独家内容。

    Sign-up for the newsletter and get the latest articles, courses, tutorials, tips, books, motivation, and other exclusive content.

    注册时事通讯并获取最新文章,课程,教程,技巧,书籍,动机和其他独家内容。

翻译自: https://www.freecodecamp.org/news/a-beginners-guide-to-git-what-is-a-changelog-and-how-to-generate-it/

git 撤销变更

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值