Pull Request 小帖士
Forked Repo
一般地,本地 forked repo 有兩個遠端:
upstream origin
更新方法
# 切換到 master 分支 git checkout master # 拉取原作者的 repo git pull upstream master:master # 更新 forked repo git push origin master:master # 更新 forked repo 的遠端分支 git remote update --prune
Pull Request 追蹤特性
pull request 會追蹤發起它的遠端分支(簡稱 PR 分支,本地副本被稱為“本地PR 分支”),除非已被 merge 或者處於 close 狀態。
- 如果 pull request 被 merge,PR 分支可以被原作者刪除。
- 如果 pull request 被 close,PR 分支可以被原作者刪除。一旦刪除,該 pull request 就不能再被 reopen。
預覽 Pull Request 合併後的狀態
首先,更新 repo。
其次,搭建預覽現場。此時完全不用擔心 conflict(除非 GitHub 網頁已經指出)。
git checkout -b [預覽分支] git pull [發起 repo 的 URL] [發起分支]
然後,預覽(一般是測試)。
最後,清理預覽現場。
git checkout master git branch -D [預覽分支]
解決 Pull Request 衝突
GitHub 的 pull request 頁面指出 PR 衝突,可用下列方法解決:
首先,更新 repo。
然後,將 master 分支合併到本地 PR 分支。此時必然發生 conflict,解決並新建 commit。建議使用 GitHub Desktop 或 IDE 來執行該步驟。
最後,push 本地 PR 發起分支。
此時,GitHub 上的 pull request 會追加 commit,並指出衝突已消除。
Pull Request 與 Issue
GitHub 中 pull request 和 issue 共用一套編號。可在頁面末尾新增的 comment,稱為 issue comment。相關的 API 都在這裡 。
如果 commit message 包含fix / fixes / fixed / close / closes / closed / resolve / resolves / resolved
等關鍵字加上#編號
,一旦 commit 被加入 repo,相應的 issue 就會被 close。