简体   繁体   English

合并一个分支的提交,以基于另一个分支

[英]Merging a commit off of one branch, to be based off of another branch

I have a master branch and a staging branch for my project.我的项目有一个master分支和一个staging分支。 I just pushed up a separate develop branch that is off of master , but I need it to be off of staging .我刚刚推出了一个独立的develop分支,它脱离了master ,但我需要它脱离staging

Is there anyway to take the develop branch which is 1 commit ahead of master and have it so it is off of my staging branch ?无论如何,是否可以采用比 master 早 1 次提交的develop分支,并让它脱离我的暂存branch So ultimately it would only be one commit ahead of staging ?所以最终它只会在staging之前提交一次?

I might be tempted to suggest doing a simple rebase of develop on staging :我可能会建议在staging上做一个简单的develop变基:

git checkout develop
git rebase staging

This would replay all the commits in develop which occurred after the point where staging diverged from master directly on top of the staging branch.这将重播所有在提交develop这点在哪里发生staging从分歧master直接在上面staging分支。 But this might also play certain master commits on top of staging , which does not sound like what you want.但这也可能会在staging之上播放某些master提交,这听起来不像您想要的。

So if all you want to do is to play that single commit on top of staging and have it be the develop branch, you can try this:因此,如果您只想在staging之上播放单个提交并将其作为develop分支,则可以尝试以下操作:

git checkout staging
git checkout -b new_develop
git cherry-pick <SHA-1 of single commit>

Then delete the old develop branch, and rename new_develop to develop :然后删除旧的develop分支,并将new_develop重命名为develop

git branch -d develop
git branch -m new_develop develop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM