Skip to content

合并拉请求-Merging Pull Requests

Challenges of integrating a Pull Request

集成拉取请求的挑战

When a Pull Request has been reviewed and is ready to be merged it's usually marked with a GG comment meaning Good to Go.

当一个Pull Request被审查并准备合并时,它通常标有__GG__评论,意思是__Good to Go__。

At this point any dev with commit rights should be able to merge it in the main repository.

此时,任何具有提交权限的开发者都应该能够将其合并到主存储库中。

However we might need to rewrite the changes to keep the repository clean:

但是,我们可能需要重写更改以保持存储库清洁:

  • By updating the commit message if it needs to be shortened or improved.

  • 通过更新提交消息,如果需要缩短或改进。

For instance if the patch is related to a work item, the commit message should look like this:

例如,如果补丁与工作项相关,则提交消息应如下所示:


\#12345: Short message

 <font color=#0099ff size=4 face="黑体">\\#12345:短信</font> 





 <font color=#0099ff size=4 face="黑体"></font> 


A longer message than can span multiple lines and describe the reasoning behind the change.

 <font color=#0099ff size=4 face="黑体">比可以跨越多行的更长的消息并描述更改背后的推理。</font> 





 <font color=#0099ff size=4 face="黑体"></font> 


Work Item: 12345

 <font color=#0099ff size=4 face="黑体">工作项目:12345</font> 


  • By rebasing the changes on the top of the branch to keep a more readable changelog.

  • 通过重新定义分支顶部的更改来保持更易读的更改日志。

  • By squashing the changes into a single commit.

  • 通过将更改压缩到单个提交中。

Doing so can be tedious depending on your level of knowledge on git.

根据您对git的了解程度,这样做可能会很乏味。

To help with this a specific git alias can be used.

为了帮助解决这个问题,可以使用特定的git别名。

GIT Alias to Merge changes from github

GIT别名合并来自github的更改

  • In your user's profile folder (e.g., c:\users\sebros) open the file .gitconfig.

  • 在用户的配置文件文件夹(例如,c:\\ users \\ sebros)中打开文件.gitconfig

  • Anywhere in the file (at the end for instance) add a new alias like this:

  • 文件中的任何位置(例如,最后)添加一个新的别名,如下所示:


[alias]

 <font color=#0099ff size=4 face="黑体">[别名]</font> 


accept-pr = "!f(){ git checkout -b PR $1 && git pull $2 $3 && git rebase $1 && author=`git log -n 1 --pretty='format:%an <%ae>'` && git reset $1 && git checkout $1 && git commit -a -m \"$4\" && git commit --amend --author=\"$author\" --no-edit && git branch -D PR; };f"

 <font color=#0099ff size=4 face="黑体">accept-pr =“!f(){git checkout -b PR $ 1 \u0026\u0026 git pull $ 2 $ 3 \u0026\u0026 git rebase $ 1 \u0026\u0026 author =`git log -n 1 --pretty ='format:%an <%ae>'`\u0026\u0026 git reset $ 1 \u0026\u0026 git checkout $ 1 \u0026\u0026 git commit -a -m \\“$ 4 \\”\u0026\u0026 git commit --amend --author = \\“$ author \\” -  no-edit \u0026\u0026 git branch -D PR;}; f “</font> 


  • If the [alias] section already exists, keep it.

  • 如果[alias]部分已存在,请保留它。

This accept-pr command is now accessible from the git console and will apply all the necessary steps.

现在可以从git控制台访问这个accept-pr命令,并将应用所有必要的步骤。

Warning

!警告

TODO: Orchard has moved to github, the following needs to be updated.

  • $1: The branch to apply the PR to, e.g., 1.8.x, 1.x

  • $ 1:将PR应用于的分支,例如1.8.x1.x *

  • $2: The url of the remote PR, e.g., https://git01.codeplex.com/forks/jchenga/orchard

  • $ 2:远程PR的URL,例如https:// git01.codeplex.com / forks / jchenga / orchard *

  • $3: The branch to pull from the remote PR, e.g., issues/20311

  • $ 3:从远程PR拉出的分支,例如issues / 20311 *

  • $4: The commit message for the squashed commit, e.g., $'#1234: Short \n Long \n Work Item: 1234'

  • $ 4:压缩提交的提交消息,例如,'$'#1234:短\ n长\ n工作项:1234' *

The parameters $2 and $3 can be found in the modal dialog which appears when clicking on the Accept link of the pull request page on codeplex.

参数$ 2$ 3可以在模式对话框中找到,该对话框在单击codeplex上的拉取请求页面的 Accept 链接时出现。

For instance it will show up a line like this:

例如,它会显示如下这样的一行:

git pull https://git01.codeplex.com/forks/jchenga/orchard issues/20797, where

  • $2 is https://git01.codeplex.com/forks/jchenga/orchard

  • $ 2https:// git01.codeplex.com / forks / jchenga / orchard

  • $3 is issues/20797

  • $ 3issue / 20797

Usage

用法


git accept-pr 1.8.x https://git01.codeplex.com/forks/jchenga/orchard issues/20797 $'#20797: Fixing taxonomy handler exception\n\nWork Item: 20797'

 <font color=#0099ff size=4 face="黑体">git accept-pr 1.8.x https://git01.codeplex.com/forks/jchenga/orchard issues / 20797 $'#20797:修复分类法处理程序异常\\ n \\ n工作项目:20797'</font> 


If this command results with an error, it's probably because the PR is too old and there are some merge conflicts. In this case reopen the PR by requesting the user to rebase his changes on the targeted branch or to merge the conflicts, clean you local changes, then try again.

如果此命令导致错误,则可能是因为PR太旧并且存在一些合并冲突。在这种情况下,通过请求用户在目标分支上重新定义其更改或合并冲突,清除本地更改,然后重试,重新打开PR。

If at this point you don't know what you doing or you have a doubt, please contact another committer for help.

如果此时您不知道自己在做什么或者您有疑问,请联系其他提交者寻求帮助。

Finally, push the commits, and mark the PR as accepted.

最后,推送提交,并将PR标记为已接受。