本文介绍了如何让一个git分支与master同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有两个分支,一个叫做主人和一个名为 mobiledevicesupport 的人。我希望将mobiledevicesupport保持为连续的分支,只要mobiledevicesupport稳定,就会与主分支合并/同步。这会将移动设备支持的更改合并到主设备中,但也会将主设备的所有更改合并到移动设备支持中,以便分支可以继续进行工作并改进或修改功能。这需要与中央存储库和多个开发人员一起工作。



请示例其他人使用的类似工作流的示例,或者告诉我这个想法是否愚蠢,我应该考虑其他人选项。目前工作流程看起来很合理,但我不知道如何让git以这种方式工作。



谢谢大家,非常感谢。



更新1:
如果我要将master到mobiledevicesupport和mobiledevice支持合并到master中,我是否可以在两个分支中获得复制提交。或者git足够聪明地解决问题,我已经将最新的更改从分支A拉到分支B,并将合并提交C添加到分支B.并且我将最新的更改从分支B拉到分支A并将合并提交D添加到分支A?

我打算发布一张图片,但是我没有足够的声望,所以我想下面的插图将不得不做。两个分支不断合并,往往双向合并。我不确定的关键是git将如何执行提交,并且它会使用来自其他分支的提交在合并时填充任一分支还是将它保持干净。我之前使用过rebase,但似乎结束了分支,并将所有提交放入master,或者我做错了。感谢您的帮助。

  master 
A - B - C ----- H- - I - J - M - N
\\ / \
mobile \ / \
D - E - F - G ------ - K - L


解决方案

p>

  git checkout master 
git pull
git checkout mobiledevicesupport
git merge master

保持移动设备支持与主设备同步

重新准备好将mobiledevicesupport放入master,首先像上面的master一样合并,然后...

  git checkout master 
git merge mobiledevicesupport
git push origin master

就是这样。



这里的假设是mobilexxx是一个主题分支,但尚未准备好进入主分支。所以当mobiledevicesupport在一个好的地方时,只能合并到master中。

At the moment git is doing my head in, I cannot come up with the best solution for the following.

There are two branches, one called master and one called mobiledevicesupport. I want to keep mobiledevicesupport as a continuous branch that will be merged/synced with the master branch whenever mobiledevicesupport is stable. This would merge changes from mobiledevicesupport into master but also bring all the changes from master into mobiledevicesupport so that branch can continue to be worked on and the features improved or amended. This needs to work with a central repository and multiple developers.

Please an example of similar workflows other people use or just tell me if this idea is stupid and I should consider other options. At the moment the workflow seems sound, but I just don't know how I can make git work this way.

Thanks, all help much appreciated.

Update 1:If I was to merge master into mobiledevicesupport and mobiledevice support into master, do I get replicated commits across both branches. Or is git smart enough to work out that I have pulled the latest changes from branch A into branch B and add merge commit C to branch B. And I have pulled the latest changes from branch B into branch A and add merge commit D to branch A?

I was going to post an image but I don't have enough reputation for it, so I guess the following illustration will have to do. Two branches continuously running with merges going both directions often. The key thing I am not sure about is how git will play out the commits and will it fill either branch with the commits from the other branch on merges or will it stay clean. I have used rebase before but it seems to end the branch and put all the commits into the master, or I did it wrong. Thanks for the help so far.

master
A--B--C-----H--I--J--M--N
       \   /    \
mobile  \ /      \
D--E--F--G--------K--L
解决方案

yes just do

git checkout master
git pull
git checkout mobiledevicesupport
git merge master

to keep mobiledevicesupport in sync with master

then when you're ready to put mobiledevicesupport into master, first merge in master like above, then ...

git checkout master
git merge mobiledevicesupport
git push origin master

and thats it.

the assumption here is that mobilexxx is a topic branch with work that isn't ready to go into your main branch yet. So only merge into master when mobiledevicesupport is in a good place

这篇关于如何让一个git分支与master同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 05:23