admin管理员组文章数量:1389890
I have an automation the needs to create a Pull Request which (once merged) forces master
to perfectly match dev
.
Doing a simple Pull Request from dev->master
seems right, but that brings dev's "new" commits to master
. master
will still maintain any "new" commits of its own. The branches may end up not matching, or the PR may cause a merge conflict.
A --force
push of dev->master
works, but those aren't possible in a Pull Request.
How can I create a Pull Request that forces master
to exactly match dev
and without merge conflicts?
(I'm answering below but hoping one of you git ninjas will confirm or tell me if there's a better way)
I have an automation the needs to create a Pull Request which (once merged) forces master
to perfectly match dev
.
Doing a simple Pull Request from dev->master
seems right, but that brings dev's "new" commits to master
. master
will still maintain any "new" commits of its own. The branches may end up not matching, or the PR may cause a merge conflict.
A --force
push of dev->master
works, but those aren't possible in a Pull Request.
How can I create a Pull Request that forces master
to exactly match dev
and without merge conflicts?
(I'm answering below but hoping one of you git ninjas will confirm or tell me if there's a better way)
Share Improve this question asked Mar 14 at 20:09 bendytreebendytree 13.6k12 gold badges80 silver badges96 bronze badges 1 |2 Answers
Reset to default 2If you mean to make master
look like in content what dev
looks like, you need to play a little bit with history... this should work:
git checkout dev
git merge -s ours master # merge master into dev.... this will *link* them in the new dev commit *but* actually dev won't change its content
If you create a PR to merge dev
into master
right now and merge it, master
will end up having exactly the same content of dev
.
Pull requests apply new commits. So it needs to see a commit which takes master
directly from its current state to dev
.
git checkout --no-checkout master
git checkout -B premaster # our starting point is master
git checkout dev -- . # our goal is for the file system to match "dev"
git commit -am "dev-to-master commit"
git push -f origin premaster # ignore any previous history to premaster
Now create pull request with head=premaster
and base=master
If this PR is merged immediately then dev
will match master
. But if master receives any new commits before the merge, then those new commits will be retained and could cause a merge conflict.
本文标签: githubHow to force Git branches to match via a PRStack Overflow
版权声明:本文标题:github - How to force Git branches to match via a PR? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744634094a2616718.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
master
that aren't indev
yet. So why do you regularly have those commits onmaster
if you wish to automate ignoring them? What does yourmaster
anddev
branch represent in your work flow? – TTT Commented Mar 17 at 14:06