[英]Github: Merge `master` branch into `feature` branch after submiting pull request
我不確定它是否可行。 我已經嘗試過一些像變基/合並這樣的事情,但無論我嘗試過什么,總是會進入 PR diff。
這就是我所擁有的和我想要的,
我有一個主(默認)分支,然后我創建了一個功能分支來進行更改並針對它提出了 PR。
現在更多更改已合並到 Master 中,我需要使用這些更改來修復評論意見(主要是一些實用程序用法和庫)。 所以,基本上我嘗試分別對兩者進行變基/合並以查看它是如何進行的,並且我總是以額外的提交作為我的 PR diff 的更改而不僅僅是我的更改。
github有什么辦法可以實現嗎? 不僅僅是創建一個新的功能分支並創建新的 PR 並放棄舊的。
編輯:
這是我試過的,
1. Using Rebase
> git checkout master
> git checkout -b feature
> // make changes & commit on feature
> git push origin feature
> git checkout master
> // made some changes & commit on master
> git push origin master
// now rebase
> git checkout feature
> git rebase master
> git push origin feature // fails as it complains HEAD being different from remote feature branch due to earlier rebase
> git pull --rebase
> git push origin feature
This set-up is adding master changes in the PR as diff and commit-id is changed in feature branch as well (expected due to rebase).
而除了 rebase 之外的相同步驟集,如果我合並,它不會顯示在 PR diff 中。
最后,在瀏覽了更多帖子之后,這里是有效的,但不會導致 PR 中彈出窗口的主更改(w/rebase 選項)
> git checkout master
> git checkout feature
> //make change & commit
> git push origin feature
> git checkout master
// make change & commit
> git push origin master
> git checkout feature
> git rebase origin/master // you can do just master to rebase against local
> git push -f origin feature // this is important otherwise you will see error and it will ask to do `git pull --rebase origin feature` which will cause master changes to appear in the diff. I feel like github has issues...and it's should do diff based on content rather than commits. but any ways
發生這種情況的原因是因為您將feature
分支的新(正確)版本重新定位在它的舊(過時)版本之上。 這不僅重寫了您的提交,還重寫了您從master
獲得的新提交,這些新提交還沒有出現在您的feature
分支的舊副本上。
您已經從評論和更新的問題中發現的解決方案可以概括為:
當你使用 rebase 工作流時,你需要在之后強制推送你的個人功能分支。
(旁注:您應該很少(如果有的話)強制推送共享分支,例如master
。)
您使用的一系列命令使您能夠跳過強制推送:
git pull --rebase
git push origin feature
意味着您將所有提交(也包括master
上的新提交)重新定位(重播)到分支的舊版本,然后將其推出。
請注意,一般來說,我很少支持顯式獲取。 因此,要使用最新的master
更新您的feature
分支,您可以根據需要經常執行此操作(但可能每天至少一次):
git fetch
git rebase origin/master feature
# If you want to update a PR, or even just backup your commits in case your machine dies
git push --force-with-lease
請注意,即使您當前沒有檢出feature
,上面的 rebase 命令也可以使用。 如果您已經簽出它,則可以省略分支名稱的最后一個參數。
這不只是基於(遠程)開發嗎? 你完全可以在打開 PR 的同時做到這一點。 為此,請檢查您的功能分支
git checkout branch
然后獲取遠程代碼中的新更改
git fetch upstream
並實施它們
git rebase upstream/master
或者
git rebase upstream/develop
取決於合並遠程倉庫中更改的位置。
順便說一句,許多人更喜歡將遠程更改合並到他們自己的master
或develop
中,然后將他們的feature
rebase 到他們自己的本地develop
中。 這是因為許多開發人員更喜歡擁有一個本地干凈的副本來使事情井井有條。
如果我遺漏了什么,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.