我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

关于拉取请求合并

您可以通过将所有提交保留在功能分支中、将所有提交压缩到一个提交中,或者将个别提交从“头部分支”变基为“基本”分支,以 合并拉取请求

本文内容

When you click the default Merge pull request option on a pull request on GitHub, all commits from the feature branch are added to the base branch in a merge commit. The pull request is merged using the --no-ff option.

To merge pull requests, you must have write permissions in the repository.

standard-merge-commit-diagram

压缩与合并拉取请求提交

When you select the Squash and merge option on a pull request on GitHub, the pull request's commits are squashed into a single commit. Instead of seeing all of a contributor's individual commits from a topic branch, the commits are combined into one commit and merged into the default branch. Pull requests with squashed commits are merged using the fast-forward option.

To squash and merge pull requests, you must have write permissions in the repository, and the repository must allow squash merging.

commit-squashing-diagram

You can use squash and merge to create a more streamlined Git history in your repository. Work-in-progress commits are helpful when working on a feature branch, but they aren’t necessarily important to retain in the Git history. If you squash these commits into one commit while merging to the default branch, you can retain the original changes with a clear Git history.

变基与合并拉取请求提交

When you select the Rebase and merge option on a pull request on GitHub, all commits from the topic branch (or head branch) are added onto the base branch individually without a merge commit. Pull requests with rebased commits are merged using the fast-forward option.

To rebase and merge pull requests, you must have write permissions in the repository, and the repository must allow rebase merging.

The rebase and merge behavior on GitHub deviates slightly from git rebase. Rebase and merge on GitHub will always update the committer information and create new commit SHAs, whereas git rebase outside of GitHub does not change the committer information when the rebase happens on top of an ancestor commit. For more information about git rebase, see the "Git rebase" chapter from the Pro Git book.

For a visual representation of git rebase, see The "Git Branching - Rebasing" chapter from the Pro Git book.

在以下情况下,您无法在 GitHub 上自动变基与合并:

  • 拉取请求有合并冲突。
  • 将提交从基本分支变基为遇到冲突的头部分支。
  • 变基提交被视为“不安全”,例如变基可行、不会发生冲突但会产生与合并不同的结果时。

如果您仍然要变基提交,但不能在 GitHub 上自动变基与合并,则您必须:

  • 在命令行上以本地方式将主题分支(或头部分支)变基为基本分支
  • 解决命令行上的任何冲突
  • 强制推送变基的命令到拉取请求的主题分支(或远端头部分支)。

在仓库中具有写入权限的任何人然后可以使用 GitHub 上的变基与合并按钮合并更改

延伸阅读

问问别人

找不到要找的内容?

联系我们