如何解释和使用Github提交页面? [英] How do I interpret and make use of Github commit pages?

查看:96
本文介绍了如何解释和使用Github提交页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个真正的菜鸟问题。我在Github上找到了一些代码,并在项目中使用了其中的一部分,后来我发现了该代码的问题,并在该项目的Github页面上提交了问题,维护人员对其进行了修复,现在该问题具有指向提交页面的链接。看起来像这样(来自此页面-不是真正的页面,但是很好地说明了问题):

This is a really noob question. I found some code on Github and used part of it in my project and later I found a problem with that code and filed an issue on that project Github page and the maintainer fixed it and the issue now has a link to a "commit" page which looks something like this (from this page - that is not the real one, but good to illustrate the problem):

而且,我想该页面包含了我的问题的解决方案,但我对如何解释它一无所知。有很多用不同颜色突出显示的代码,而我只是不了解发生了什么。

and well, I guess that page contains the solution to my problem but I don't have a slightest idea of how to interpret it. There're lots of code highlighted with different colors and I just don't get what's going on.

我如何解释并使用这样的提交页面?

How do I interpret such a commit page and make use of it?

推荐答案

由于这是一个新手问题,答案将忽略您在该页面上看到的核心详细信息,例如父提交和在大多数情况下不重要的其他事项。所以我们开始...

Since this is a newbie question the answer will omit the hardcore details which you see on that page such as "parent commit" and other things which are not important in most cases. So here we go...

该页面不显示一些代码,而是显示如何更改一些代码。由于您说提交是从您提交的问题中引用的,因此您可以假定此提交中的更改可以解决问题。

That page doesn't show some code, instead it shows how some code was changed. Since you say the commit was referenced from the issue you filed you can assume that changes in this commit resolve the issue.

提交页面显示了一组更改-插入,删除和替换(插入和删除的组合)。以下是您提供的带有注释的图像的一部分:

The commit page shows a set of changes - insertions, deletions and replacements (combination of insertion and deletion). Below is part of the image you provided with annotations:

最上面是文件名。每个更改都发生在某个文件中。文件名是相对于项目根目录的。一次提交可以包含一个或多个更改,并且每个更改都属于某个文件,并将与该上下文信息一起显示。请注意,更改会从第2969行开始显示-为简洁起见,因此无需滚动至更改。如果您需要查看该代码的内容,可以使用文本扩展按钮。您还可以使用页面区域右上角显示特定文件的查看按钮来查看整个文件。

On top is the name of the file. Each change happens in some file. File names are relative to project root. A commit can contain one or more changes and each will belong to some file and it will be displayed with this contextual information. Note that the change is displayed starting with line 2969 - this is done for brevity so that you don't need to scroll to the change. If you need to see what was around that code you can use the text expansion buttons. You can also use "View" button somewhere in the top right corner of the page region showing a specific file to see the entire file.

请注意其优缺点。减号表示删除了一些行,加号表示添加了一些行。这里有三个选项-仅添加(当在文本的某些位置插入行时),仅删除(当某些行被删除时)和替换(它们的组合)。

Note the pluses and minuses. Minuses mean some lines were removed and pluses mean some lines were added. There're three options here - additions only (when lines are inserted in some position of the text), deletions only (when some lines were deleted) and replacements which are combinations thereof.

在上图中,您看到一个替换。第2972行以前包含一些代码,但已替换为两行新代码。因此,删除了一行,插入了两行。请注意,尽管行号在更改之前匹配-它们像 2969-2969, 2970-2970等,但是在更改后它们不再匹配-现在它们像 2973-2974等。因为用两行替换一行将代码移到更改下方,更改后的所有行号都偏移一个。

On the image above you see a replacement. Line 2972 previously contained some code which was replaced with two lines of new code. So it's removal of one line and insertion of two lines. Note that although the line numbers match before the change - they go like "2969-2969", "2970-2970", etc, they no longer match after the change - now they go like "2973-2974", etc. This happened because replacing one line with two new lines moves the code below the change and all the line numbers after the change are offset by one.

下图显示了单独的插入和单独删除:

The following image shows a separate insertion and a separate deletion:

请注意,第890行与第896行对齐,因为在其上方有其他更改会偏移文本。如果此更改是文件中的第一个更改,则这些编号将彼此匹配。首先是插入-作者决定在更改后的899行插入带有变量声明的新行。然后进行删除-作者决定从928行(更改前的数字)中删除带有变量声明的行。在这种特定情况下,这两个更改发生在同一函数中,并且作者有效地将变量声明从一个位置移到了另一个位置。插入不一定要伴有删除,如果确实如此,则插入不一定与此处相关。作者可能找到了一个未使用的变量,只是删除了声明-不会插入任何内容。

Note that line 890 is aligned with line 896 because of other changes above which offset the text. If this change was the first one within the file those numbers would have match each other. First comes the insertion - the author decided to insert a new line with a variable declaration which is line 899 after the change. Then comes a deletion - the author decided to remove the line with a variable declaration from line 928 (number before the change). In this specific case the two changes happened in the same function and the author effectively moved the variable declaration from one place to another. Insertions are not necessarily accompanied by deletions and if they are then those are not necessarily relevant as here. The author might have found an unused variable and just removed the declaration - nothing would be inserted.

所以这就是您在页面上看到的。

So this is what you see on the page.

您应该做什么取决于多个因素。

What you should do depends on multiple factors.

如果您使用建议的Github流程(这不是绝对必要的,所以不要'不会立即感到不高兴)并分叉项目并编辑您可能已经合并更改的叉子-通常可以半自动完成。

If you were using the recommended Github flow (this is not absolutely necessary, so don't get upset immediately) and forked the project and edited the fork you could have "merged" the changes - this can often be done semi-automatically.

但是您的问题提示您刚刚下载了代码并在本地对其进行了编辑。如果是这种情况,则必须在项目中找到相关代码(在每次更改附近使用文件名和函数名),并适当地更改代码副本。

However your question hints that you just downloaded the code and edited it locally. If that's the case you have to locate relevant code in your project (using file names and function names near each change) and change your copy of the code appropriately.

这篇关于如何解释和使用Github提交页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆