问题
The repository I am working with has 3 branches: Master, Demo, and Development. Things that have been properly tested go from Development into Demo. After Demo, it goes into Master and then deployed.
When working on changes, I pull from the Demo branch, the most stable branch with newest features, and create a local branch.
To put my changes for testing I need to merge them into the Development branch. But not everything on the Development branch is ready to go into the Demo branch.
Is there a way I can merge my change into the Development branch, where if my change is OK'd, I then merge my branch into the Demo branch, but without bringing in any of the code from Development?
Apologies if this is a beginner question and confusing title.
回答1:
yes, you can test your dev branch before merge it:
1) create a branch ex: task1: git checkout -b task1
2) when you're done with these changes, commit and push into this branch
3) then do a merge request (gitlab concept) or pull request (github concept)
4) now its time to test this branch locally :
4-1) git fetch origin
4-2) git checkout -b task1 origin/task1
5) now you are able to view changes locally, if ok then try to merge it :
5-1)
git fetch origin
git checkout origin/master
5-2) merge this branch:
git merge --no-ff task1
resolve conflict and correct error if exist then push this version if is perfect into your branch ex : master:
git push origin master
if you are detached from head message shown then do this instead :
git push origin HEAD:master
回答2:
If I understand your flow correctly, then you pull from Demo and branch out into a new branch. This branch you merge to Development in order to do tests there. You can use the same branch and merge it as well to Demo afterwards. But passing tests in Development will not ensure that it will also work on Demo since the code differs.
Instead, you could pull from Development and then branch out to a feature branch in order to develop your feature. Once it is ready you could merge back to Development and test it. If all tests pass you could merge to Demo. This way you ensure that you have the same code passed all the tests is also in branch Demo and you will not have any surprises on Demo.
If you have features on Development which should not enter Demo, then you could hide them by using feature toggles.
来源:https://stackoverflow.com/questions/61431376/git-merge-local-branch-to-remote-branches-a-and-b-without-inserting-code-from-a