Select commits from gitlab develop branch to create merge request to main

42 views Asked by At

I have develop and main branches on gitlab. I want to create a merge request from develop to main includes a part of commits. Some of commits should be in merge request. What should I do?

I tried git cherry pick but it take a lot of times

2

There are 2 answers

0
eftshift0 On

git cherry-pick is the way to go if you only intend to include some of the commits from a branch... you need to set them apart and then cherry-pick should do it.... you might also consider creating a different branch using rebase interactive to select which commits to include.... say, something like:

git branch some-branch develop
git rebase -i master some-branch
# you will have an editor with a lot of commits that say _pick_
# keep that in the commits you want to include, delete the lines
# for the ones you don't want _or_ set them to `skip`
# save and continue
# and when rebase is done (you might get conflicts on the way)
# you will have your selection of commits so that you can
# create the PR
0
Torge Rosendahl On

If you want to keep most commits on the dev branch, you could instead remove the commits you do not want.

I would suggest creating a new working branch to not lose any commits (as a copy of develop) and then removing all commits you do not want to merge from that branch.

You can remove commits by rebasing whatever comes after that commit on the commits parent, see How do I delete a commit from a branch?.