Github 如何更新 pull request

本篇 ShengYu 介紹 Github 如何更新 pull request,通常提交改動給原專案後,等 reviewer 看過沒問題後就會 merge,但是如果 reviewer 覺得哪些地方需要你再修改的話,你就需要學會如何更新你已經提交過的 pull request,

假設今天你已經有一個改動在 fix-xxx 的 branch 並且已經提交 pull request 了,
然後原專案 reviewer 需要你再做一些修改,
在 fix-xxx branch 修改完後直接使用下列指令 commit 起來,這樣的方式是修改原本的 commit 內容,
在很多時候原專案希望你的後續的改動不要另外新增一筆 commit 時就需要這麼做,

1
2
git add -A # 加入你的改動
git commit --amend # 修改前一次的 commit

再用強制更新的方式將改動推上遠端的 fix-xxx branch 去,

1
git push origin fix-xxx --force

接下來不用作任何事情,github 會自動將你的改動更新到原本的 pull request 去,
所以接下來去原專案的 pull request 頁面重新整理一下,就可以看到你的新的更新了。

其它參考
How to amend a commit on a GitHub Pull Request
https://www.burntfen.com/2015-10-30/how-to-amend-a-commit-on-a-github-pull-request
How to update a pull request ?
https://github.com/github/hub/issues/198
Github 發 Pull Request & 貢獻流程速查
https://gist.github.com/timdream/5968469

其它相關文章推薦
Github 提交你的修改貢獻到開源專案
Github 如何更新已經 fork 的專案與原專案紀錄同步
Git 顯示某個檔案的歷史修改記錄
Git 顯示整個repository的歷史修改記錄