简体   繁体   中英

Gitlab merge two branches

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.

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 ?

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.

From the command line, after you revert to a commit before the gitlab merge, check out the dev branch and merge preprod into it:

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").

Links to the git tools I mentioned: git extensions: https://sourceforge.net/projects/gitextensions/ SourceTree: https://www.sourcetreeapp.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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