Gerrit 简明教程

Gerrit - Make & Commit Your Change

当您修改本地文件系统中的代码时,您可以使用以下命令检查目录中的更改。

When you modify the code in the local file system, you can check for the changes within the directory using the following command.

$ git diff

在项目目录中,我们将修改名为 Example/Example.hooks.php 的文件中的某些更改并运行上述命令。我们会获得如下图所示的结果。

In the project directory, we will modify some changes in the file called Example/Example.hooks.php and run the above command. We will get the result as shown in the following screenshot.

gerrit commit changes

您可以使用以下命令检查对文件或目录所做的更改。

You can check the changes made to the files or the directory using the following command.

$ git status
gerrit commit changes1

上述命令允许查看哪些更改已暂存,哪些更改未暂存,以及哪些文件未被 Git 跟踪。

The above command allows to see which changes have been staged, which have not, and which files are not tracked by Git.

接下来,您可以使用以下命令将更改添加到工作目录并在下一次提交中更新文件。

Next, you can add the changes in the working directory and update the file in the next commit using following command.

$ git add Example/Example.hooks.php

添加文件后,再次运行 git status 命令以查看添加到暂存区域的更改,如下图所示。

After adding the file, again run the git status command to review the changes added to the staging area as shown in the following screenshot.

gerrit commit changes2

您可以使用以下命令查看索引和上次提交之间的差异,以及暂存了哪些内容。

You can see the difference between the index and your last commit, and what contents have been staged, using the following command.

$ git diff --cached
gerrit commit changes3

你可以使用以下命令将变更从本地存储库推送到远程目录。

You can push the changes to the remote directory from the local repository using the following command.

$ git commit

当你运行上述命令时,它会要求添加对你的变更进行提交的消息。当你在其他存储库中推送提交时,其他人在看到该提交时会看到此消息。

When you run the above command, it will ask to add the commit message for your changes. This message will be seen by other people when you push the commit to the other repository.

gerrit commit changes4

添加提交消息,然后再次运行命令,例如 git commit,它会显示提交消息,如下图所示。

Add the commit message and run the command again as git commit, which will display the commit message as shown in the following screenshot.

gerrit commit changes5