Skip to main content

Pull request

拉取請求可讓您通知其他貢獻者有關 Git 分支的變更。 拉取請求時,您可以先討論並評估建議的變更,然後再將變更執行到主分支。

您最終可以透過建立拉取請求,將變更合併回主儲存庫 (或 repo)。 但是,需要注意的是,在對原始代碼進行任何變更之前,GitHub 會創建一個 fork(或專案的副本),即使變更無法推送到另一個 repo,也可以將變更提交到 fork 副本。

任何人都可以透過拉取請求中的內嵌註解提出變更建議,但在合併變更之前只有擁有者有審查和批准變更的權利。 若要建立拉取請求:

  • Make changes to the file.

  • Change the proposal and complete a description of the change.

  • Click the Proposed File Change button to create a commit in the forked repo to send the change to the owner.

  • Enter comments about the change. If more context is needed about the change, use the text box.

  • Click Pull Request.

官方教學:Creating a pull request

您可以通過保留提交來合併拉取請求。 以下是您在合併拉取請求時可以使用的拉取請求合併選項清單。

  • Merge commits. All commits from the feature branch are added to the base branch in a merge commit using the -- no–ff option. 
  • Squash and merge commits. Multiple commits of a pull request are squashed, or combined into a single commit, using the fast-forward option. It is recommended that when merging two branches, pull requests are squashed and merged to prevent the likelihood of conflicts due to redundancy.
  • Merge message for a squash merge. GitHub generates a default commit message, which you can edit. This message may include the pull request title, pull request description, or information about the commits.
  • Rebase and merge commits. All commits from the topic branch are added onto the base branch individually without a merge commit. 
  • Indirect merges. GitHub can merge a pull request automatically if the head branch is directly or indirectly merged into the base branch externally.