关于 GitHub 上的合并方法
您可以允许能够推送到仓库的贡献者使用不同的合并选项在 您的 GitHub Enterprise Server 实例 上合并其推送请求,或者对所有仓库的拉取请求实施特定的合并方法。
您可以在 您的 GitHub Enterprise Server 实例 上配置拉取请求合并选项 以满足工作流程需求以及管理 Git 历史记录的首选项。 您可以只对仓库启用所需的方法,以实施一种合并方法,如提交压缩或变基。
When you click the default Merge pull request option on a pull request on 您的 GitHub Enterprise Server 实例, 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.
压缩合并提交
When you select the Squash and merge option on a pull request on 您的 GitHub Enterprise Server 实例, 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.
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.
在启用压缩提交之前,请考虑以下缺点:
- 您会丢失关于最初何时执行了特定更改以及是谁进行了压缩提交的信息。
- 有些使用 "SHA" 或“哈希”ID 的 Git 命令可能更难使用,因为原始提交的 SHA ID 已经丢失。 例如,使用
git rerere
可能不像以前一样有效。
更多信息请参阅“为拉取请求配置提交压缩”。
变基和合并提交
When you select the Rebase and merge option on a pull request on 您的 GitHub Enterprise Server 实例, 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 Enterprise 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 Enterprise Server 实例 上使用 Rebase and merge(变基和合并) 选项。 强制推送必须谨慎执行,以免贡献者覆盖别人在其工作基础上所做的工作。 要详细了解何时在 您的 GitHub Enterprise Server 实例 上禁用 Rebase and merge(变基和合并)选项以及重新启用它的工作流程,请参阅“关于拉取请求合并”。
更多信息请参阅“为拉取请求配置提交变基”。