[ English | English (United Kingdom) | 中文 (简体, 中国) | Indonesia | 한국어 (대한민국) | español (México) | Deutsch ]

设置和学习Git

备注

本章节假设您已完成 帐户设置 指南。

Git

什么是Git?

Git是一个免费的开源分布式版本控制系统,OpenStack社区用它来管理对源代码和文档的更改。

Git允许您:

安装

Mac OS

  1. 前往 Git 下载页面 并点击 Mac OS X.

  2. 下载的文件应该是您下载文件夹中的dmg文件。 打开该dmg文件并按照屏幕上的说明操作。

如果使用包管理器 Homebrew ,打开一个终端并输入:

brew install git

Linux

对于像Debian、Ubuntu或Mint这样的发行版,打开终端并输入:

sudo apt install git

对于像RedHat、CentOS、Fedora 21或更早版本的发行版,打开终端并输入:

sudo yum install git

对于Fedora 22或更高版本打开终端并输入:

sudo dnf install git

对于SUSE发行版,打开终端并输入:

sudo zypper in git

Windows

Windows的Linux子系统 (WSL,Windows Subsystem for Linux ) 可在Windows 10 周年更新或更高版本(版本1607+)中使用。 可以安装和运行现代Linux操作系统:

所有常见的工具,如bash,git和SSH都可以直接使用。

虽然Git 下载页面 提供了Windows安装文件,但遗憾的是,大多数OpenStack开发工具(例如git-review)在Windows环境下都无法正常工作。

配置 Git

一旦安装了Git,就需要对其进行配置。 打开终端应用程序并发出以下命令,输入您的姓/名和电子邮件地址。 这也是识别您的贡献的方式:

git config --global user.name "Firstname Lastname"
git config --global user.email "your_email@youremail.com"

备注

使用帐户设置期间使用的相同电子邮件地址。

学习 Git

您可以使用 Git Immersion 来学习git的教程。

作为参考,使用 Git 参考(reference )和速查(cheat sheet)

提交(commit)消息

提交消息是审阅者看到的第一件事,并在git日志中用作描述。 它们提供了仓库中更改历史记录的描述。 合并补丁后,无法修改提交消息。

格式:

  • 摘要行

  • 空行

  • 正文

  • 空行

  • Footers

备注

Footers should be entered one per line with no empty lines between them.

摘要行

摘要行简要描述了补丁内容。 字符限制为50个字符。 摘要行不应以句点结尾。 如果在提交时更改仍未完成,请在提交消息开头加上 WIP。

正文

正文包含正在解决的问题的解释,解决问题的原因,解决方案的描述,以及有关如何改进代码结构的其他可选信息,或者对其他相关补丁的引用等。 每行限制为72个字符。 正文应包含与问题相关的所有重要信息,而不假设读者理解问题的根源或访问外部网站。

Footers

Footers are lines in the final paragraph of a commit message, used to link the change to other tools.

The following footer is required:

  • The Change-Id line is a unique hash describing the change, which is generated automatically by a Git commit hook when you initially save a commit message. This should not be changed when rebasing a commit following review feedback, since it is used by Gerrit, to track versions of a patch. It won’t appear when you’re editing a new commit message for the first time, but if you commit --amend later you will see it.

StoryBoard specific footers:

  • Task: 1234:此更改对应的Storyboard的任务编号。 这将在您推送补丁时自动将任务更新为“审核”状态,并分配给您。

  • Story: 1234567:此更改所属任务对应的Storyboard事件编号。 这将发布对文章的评论并指向您的补丁的链接。

Launchpad specific footers:

  • Closes-Bug: #123456789:如果提交旨在完全修复并关闭被引用的bug,请使用 Closes-Bug 。数字则是该bug的Launchpad ID; Gerrit会自动创建一个指向该bug的链接。

  • Partial-Bug: #123456789:如果提交只是部分修复而需要更多工作,请使用 Partial-Bug 。数字则是该bug的Launchpad ID; Gerrit会自动创建一个指向该bug的链接。

  • Related-Bug: #12456789:如果提交仅与引用的bug有关,请使用 ‘Related-Bug’ 。数字则是该bug的Launchpad ID; Gerrit会自动创建一个指向该bug的链接。

  • Partial-Implements: Use this footer if the change partially implements a Launchpad blueprint. Use the name of the blueprint as an ID.

  • Implements: Use this footer if the change fully implements a Launchpad blueprint. Use the name of the blueprint as an ID.

The following footers are optional; however, their use is recommended if they are applicable to the patch:

  • The DocImpact footer contains a comment about why the change impacts documentation. Put DocImpact on a line by itself. Use this footer to indicate that documentation is either contained in the patch or has documentation impact. When this footer is included in a commit message, Gerrit creates a bug for the project affected by the change for task tracking, or move to the openstack-api-site as needed.

  • The APIImpact footer contains a comment about why the change impacts a public HTTP API. Put APIImpact on a line by itself. Use this footer to indicate that the patch impacts a public HTTP API. When this footer is included in a commit message, the API_Working_Group can use it to help find relevant reviews.

  • The SecurityImpact footer is used to indicate that a change has security implications and should be reviewed by the OpenStack Security Group.

  • The UpgradeImpact footer contains a comment about why the change impacts upgrades. It is used to indicate that a change has upgrade implications for those doing continuous deployment or N to N+1 upgrades. Also consider updating the ‘Upgrade Notes’ section in the release notes for the affected project.

  • The Depends-On: <gerrit-change-url> footer is used to refer to a change the current one depends on. Use the permalink of the change.