简体   繁体   中英

Can we create different Merge requests with same feature branch in Gitlab?

How can we create different Merge requests with same branch? I'm working as example with the branch feature/task1 . I commited those changes and created one Merge Request. Now I want to use the same feature branch but I want to create a new Merge Request. How can I achieve this?

If what you mean to do is split work on a feature in multiple partial PRs, sure there is no problem. However, you need to be careful with a number of scenarios:

push second part of the feature

Need to be careful not to push into the same remote branch as the first part if it hasn't been merged yet. If you did that, the first PR would be updated to include the changes that you mean to include in the 2nd PR.

Another problem is how you want people to see your changes in the PR. If you provide main (for example) as the target branch, then the PR will show all changes, including the ones of the first PR. In cases like this I set the target branch to be the first PR branch so that only the changes of the second PR are visible. When the first PR is merged, then I change the target branch to be the real target branch.

Careful if you decide to rebase

If you develop the second part of the feature and you decide to rebase, you need to make sure to also rebase the changes of the first PR.

So, if could be done like this (after fetching, if working with a remote)

git checkout first-part-of-feature
git branch temp # leave a temp branch over here, we will need it later
git rebase upstream/main # or whatever branch
git push # push into the remote branch
# now let's rebase the second part of the feature branch
git rebase --onto first-part-of-pr temp second-part-of-pr
# and now you got the second part on top of the first part
# and now you can push

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