git Gitlab 合并两个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40610003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gitlab merge two branches
提问by SGN
We have created 'dev' branch from the 'master' and have been working on the 'dev' branch. We have not merged the 'dev' to 'master' yet. Also at the same time we have created 'preprod' branch from the 'master' and working on the 'preprod' branch changes. We have not merged the 'preprod' to 'master' yet.
我们已经从“master”创建了“dev”分支,并且一直在“dev”分支上工作。我们还没有将“dev”合并到“master”。同时,我们从“master”创建了“preprod”分支,并致力于“preprod”分支的更改。我们还没有将“preprod”合并到“master”。
Now what we are trying to achieve is to merge the 'preprod' changes alone to 'dev'. I tried this by creating a merge request through Gitlab and approved it. What I found is the changes in the 'dev' code was also moved to 'preprod' and vice versa. I do not want the 'dev' changes to be moved to the 'preprod' by any chance. How can i accomplish this ?
现在我们试图实现的是将“preprod”更改单独合并到“dev”。我通过 Gitlab 创建合并请求并批准了它。我发现“开发”代码中的更改也移至“预生产”,反之亦然。我不希望任何机会将“开发”更改移至“预生产”。我怎样才能做到这一点?
回答by Andrew
If you got changes on both, it is likely that your merge request told gitlab to merge the two branches into each other, which is sometimes desirable. Depending on your development process, you may find it easier to use git itself (or a gui for it, for example git extensions or sourcetree) to do your merges. GUI versions do a good job of visually showing your branches and past merges, which makes it a lot easier to figure out which commands to run.
如果您对两者都进行了更改,则可能是您的合并请求告诉 gitlab 将两个分支相互合并,这有时是可取的。根据您的开发过程,您可能会发现使用 git 本身(或它的 gui,例如 git extensions 或 sourcetree)来进行合并更容易。GUI 版本在直观地显示您的分支和过去的合并方面做得很好,这使得找出要运行的命令变得容易得多。
From the command line, after you revert to a commit before the gitlab merge, check out the dev branch and merge preprod into it:
在命令行中,在 gitlab 合并之前恢复到提交后,检查 dev 分支并将 preprod 合并到其中:
git checkout dev
git merge preprod
The preprod changes will be made on dev but not vice versa (don't forget to push dev). The git merge command's effect is to merge changes from the named branch in the command (preprod) INTO the CURRENT branch (in this case dev, but you can verify the current branch running "git branch" or "git status").
preprod 更改将在 dev 上进行,反之亦然(不要忘记推送 dev)。git merge 命令的作用是将命令(preprod)中指定分支的更改合并到当前分支(在本例中为 dev,但您可以验证当前分支运行“git branch”或“git status”)。
Links to the git tools I mentioned: git extensions: https://sourceforge.net/projects/gitextensions/SourceTree: https://www.sourcetreeapp.com/
我提到的 git 工具的链接:git 扩展:https://sourceforge.net/projects/gitextensions/ SourceTree:https: //www.sourcetreeapp.com/