0

I tried the solution from this question already Remove other peoples' commits on my branch after rebase gone wrong , but didn't work for me.

My commit log looks like this:

commit somehash123 (HEAD -> feature/Clean-Branch, origin/feature/Clean-Branch)
Author: Me
Date:   Thu May 27 11:26:56 2021 +0200

     #my commit

commit somehash123abc
Author:someone else
Date:   Thu May 27 07:03:13 2021 +0000

    #somebody elses commit

commit somehash123abc
Author: someone else
Date:   Wed May 26 15:47:17 2021 +0200

    #somebody elses commit

commit somehash123abc
Author: someone else
Date:   Wed May 26 13:25:09 2021 +0000

    #somebody elses commit

and I see 4 commits (one is mine and rest are not) in the Merge request I created in GitLab. I will not be merging to master but some other feature branch.

How can I have only my commit in the branch and MR (it is a bit confusing for the code reviewer to see the other commits)? I also tried to 'cherry-pick' just my commit into a new branch, but it shows merge conflicts for merging into the 'other feature branch'

knittl
  • 246,190
  • 53
  • 318
  • 364
roma
  • 141
  • 5
  • 18
  • Could you kindly provide a more detailed log by `git log --oneline --decorate --graph --all`? – Antonio Petricca May 28 '21 at 08:51
  • Did you branch from the branch you are planning to merge to? Because Gitlab will show all commits that are on your branch and not on the target branch. If, for example, you branched from `master`/`main` but plan to merge to a feature branch that doesn't have everything that `master`/`main` has, then those extra commits will show up on the pull request. To avoid that branch directly from the desired destination branch and cherry-pick your commit onto that. – Joachim Sauer May 28 '21 at 08:55
  • @JoachimSauer it worked actually, i was doing something wrong i guess, that i was getting many other commits. Thanks! – roma May 31 '21 at 12:49

2 Answers2

0

You can rebase your single commit to your target branch, before creating the MR (or even after the MR, but you have to force-push)

git rebase --onto $your_target_branch feature/Clean-Branch^ feature/Clean-Branch

Then force-push to update the remote branch in the origin repository:

git push origin +feature/Clean-Branch:feature/Clean-Branch
knittl
  • 246,190
  • 53
  • 318
  • 364
0

Another easy solution is to create a new branch based on the target branch and cherry pick the commit using

git checkout new-branch

git cherry-pick

Push the branch to be merged into target.

roma
  • 141
  • 5
  • 18