git 如何使用 Gitlab 设置代码审查?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17559719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:30:56  来源:igfitidea点击:

How to set up a code review using Gitlab?

gitgitlabpull-request

提问by djc6535

How does one set up a code review using Gitlab? I see it listed as a feature on the Gitlab website, but I can't seem to find instructions on how to set one up (For that matter, any link to a Gitlab user manual would be most appreciated).

如何使用 Gitlab 设置代码?我看到它被列为 Gitlab 网站上的一项功能,但我似乎找不到有关如何设置的说明(就此而言,任何指向 Gitlab 用户手册的链接都将不胜感激)。

Some of my searching has indicated that 'Merge Requests' are the way to go... but I'm finding them limiting. An issued merge request shows all of the commits between one branch and the other. I seem to only be able to view diffs generated for each individual commit. For example, let's say I have a file I want to review. It is a new file but I've submitted changes to it over 10 commits on a dev branch. If I issue a merge request for that dev branch from integration I see 10 commits each of which show the incremental changes made to the file... I want to review the entire thing. It is new!

我的一些搜索表明“合并请求”是要走的路......但我发现它们有限制。发出的合并请求显示一个分支和另一个分支之间的所有提交。我似乎只能查看为每个单独提交生成的差异。例如,假设我有一个要查看的文件。这是一个新文件,但我已经在 dev 分支上提交了超过 10 次提交的更改。如果我从集成中为该开发分支发出合并请求,我会看到 10 个提交,每个提交都显示对文件所做的增量更改...我想查看整个内容。它是新的!

Am I barking up the wrong tree here? Is there an actual code-review tool I can use in GitLab, or are merge requests the way to go, and if they are am I using them incorrectly? what's the best way to set up a proper code review here?

我在这里吠错树了吗?是否有我可以在 GitLab 中使用的实际代码工具,或者合并请求是否可行,如果是,我是否错误地使用了它们?在这里设置适当的代码的最佳方法是什么?

回答by VonC

Note: since GitLab 6.4, side-by-side diff viewis available: see "pull request 5308".

注意:从 GitLab 6.4 开始,可以使用并排差异视图:请参阅“ pull request 5308”。

(July 2013)There is no possibility yet to comment on each line though, only at the file level.
Daniel Sokolowskimentions in the commentsthat Per line comments are now supported(09/2014):

(2013 年 7 月)不过,目前还无法对每一行进行评论,只能在文件级别进行评论。
Daniel Sokolowski在评论中提到现在支持每行评论(09/2014):

Your team members can comment on the merge request in general or on specific lines with line comments.

您的团队成员可以对合并请求进行一般性评论,也可以对带有行注释的特定行进行评论。

That still can help for code review activity.

这仍然有助于代码活动。

https://f.cloud.github.com/assets/4224518/1558702/e0fe633a-4fa3-11e3-9388-3f3e445cb6d4.png

https://f.cloud.github.com/assets/4224518/1558702/e0fe633a-4fa3-11e3-9388-3f3e445cb6d4.png

回答by Herberth Amaral

I've been doing code reviews in Gitlab for over two months with almost no friction. I've setup rss2emailto send email notifications everytime a developer pushes new commits. Then I use Gitlab's comment feature for commits to make some comments about the pushed code.

我在 Gitlab 中进行代码已经两个多月了,几乎没有任何摩擦。我已经设置了rss2email以在开发人员每次推送新提交时发送电子邮件通知。然后我使用Gitlab 的comment 功能进行commits 对推送的代码做一些评论。

Unfortunately, Gitlab does not allow comments on files itself, only in commits (just like Github, I guess). Whenever I find myself in a situation that I need to comment something that I've missed in a previous commit, I use the blame tool to find the commit that introduced/changed the code section to be commented.

不幸的是,Gitlab 不允许对文件本身进行评论,只允许在提交中(就像 Github,我猜)。每当我发现自己需要评论之前提交中遗漏的某些内容时,我都会使用blame工具来查找引入/更改要评论的代码部分的提交。

It is far from perfect, but it is working good so far.

它远非完美,但到目前为止运行良好。

回答by Paul Verest

You can see submitted code in Merge Request for other repository or in current repository.
example http://demo.gitlab.com/diaspora/diaspora/commits/master

您可以在其他存储库或当前存储库的合并请求中查看提交的代码。
示例http://demo.gitlab.com/diaspora/diaspora/commits/master

Then you can add comments to committed file changes (button Reply) or to the whole commit

然后您可以向提交的文件更改(按钮Reply)或整个提交 添加注释

example http://demo.gitlab.com/diaspora/diaspora/commit/42f47626890218a180870bc3f44ec57625b0779c

示例http://demo.gitlab.com/diaspora/diaspora/commit/42f47626890218a180870bc3f44ec57625b0779c

The resulting communication is code review. However, I personally recommend to do code review on one PC with face-to-face communication whenever possible, and use tools for recording results or when more formality is needed.

由此产生的交流是代码。但是,我个人建议尽可能在一台 PC 上进行代码,并进行面对面的交流,并使用工具来记录结果或需要更多形式。

For a file revue that has a lot of commits, e.g. http://demo.gitlab.com/diaspora/diaspora/blame/master/README.mdlook at it using blameto understand who did what. However in this view there is no option to communicate and add comments. I would recommend just add changes as comments in this case.

对于有很多提交的文件评论,例如http://demo.gitlab.com/diaspora/diaspora/blame/master/README.md查看它blame以了解谁做了什么。但是,在此视图中,无法进行交流和添加评论。在这种情况下,我建议只将更改添加为注释。

回答by onionjake

Yes. Merge requests are how peer reviews are accomplished.

是的。合并请求是同行评审的完成方式。

There should be a 'diff' tab that will show the changes of all the commits (mentioned here: http://youtu.be/DyAX8ws5OIc?t=3m2s).

应该有一个“差异”选项卡,将显示所有提交的更改(此处提到:http: //youtu.be/DyAX8ws5OIc?t=3m2s)。

The video also explains nicely how it can be used to peer review.

该视频还很好地解释了如何将其用于同行评审。

回答by HankCa

The normal use-case of code reviews is to review code on a branch before merging into master or similar. I have a situation where I've developed a project and want all the code to be reviewed by everyone on the team.

代码的正常用例是在合并到 master 或类似分支之前分支上的代码。我有一种情况,我开发了一个项目,并希望团队中的每个人都所有代码。

What I did was:

我所做的是:

Checkout the first commit, make a change to it, commit and push

签出第一个提交,对其进行更改,提交并推送

git co -b FIRST_COMMIT eb67f06c2b3222c0219214b176c41922bc454881
vi README.md
git add README.md
git ci -m "First commit modified so can get full diff against it"
git push --set-upstream origin FIRST-COMMIT

Checkout the last commit, make a change to it, commit and push

签出最后一次提交,对其进行更改,提交并推送

git co -b master
vi README.md
git add README.md
git ci -m "Last commit modified so can get full diff against it"
git push --set-upstream origin LAST-COMMIT

On GitLab / GitHub, create a pull request

在 GitLab / GitHub 上,创建一个拉取请求

  • It is one merging from LAST_COMMIT to FIRST_COMMIT
  • 它是从 LAST_COMMIT 到 FIRST_COMMIT 的合并

Works for me!

对我来说有效!