GitLab prevent commits to existing merge request

78 views Asked by At

I created a merge request with 10 commits from the feature branch to the main branch. The merge request is not yet closed, mean while created another commit in the feature branch. New commit is automatically added to the existing merge request. But I don't want to include the new commits to the existing merge request.

How can we prevent the new commits to existing merge requests?

2

There are 2 answers

0
Egor On

It is not possible to do so within the same branch. The easiest way will be to create new branch from the existed one and continue to commit to the new created branch.

0
Shalu Gupta On

create a new branch from the commit before the new changes. Cherry-pick the commits you want to include in the new branch. Push the new branch to the remote repository. Create a new merge request from the new branch.

git checkout -b new-feature-branch <commit_before_new_changes> git cherry-pick ... git push origin new-feature-branch

amend the last commit on your feature branch with the changes from the new commit. Force push the branch to the remote repository (Note: Be cautious with force pushing, especially if others are working on the same branch).

git add git commit --amend git push origin feature-branch --force git rebase -i <commit_before_new_changes> git push origin feature-branch --force