简体   繁体   中英

git merge request only feature branch commits

I will try to explain my problem as best I can:

  1. We have our master branch with the following commits: C1, C2, C3
  2. I created my own feature branch from master and pushed one commit, so I will have: C1, C2, C3, C4
  3. Meanwhile, the master branch has progressed with another commit, so we have: C1, C2, C3, C5
  4. I rebase my feature branch from the master one and I obtain: C1, C2, C3, C4, C5

The problem is when I create a merge request from my feature branch to the master one, my merge request will have two commits to be merged: C4, C5 (here C5 have a different hash from that of the master C5 commit).

My question is is there any way to merge only my commit C4 since C5 is already in the master branch?

Rebasing feature on top of master should result in the sequence of commits: C1, C2, C3, C5, C4

Try re-running your rebase:

# from your 'feature' branch :
git checkout feature

# rebase on 'master' :
git rebase master

# your 'feature' branch should be rewritten, with commits 1,2,3,5,4
# please add a comment if this is not the case

Once this is sorted, push your branch (you will need to use --force ), and check your merge request: it should mention only C4

You can just merge your branch into the main branch and it will only merge changes you have made, it wont merge the code twice. It may display the commits weird when you do it, but if you look at your changes you will only have changes listed as being from your 4th commit. (if I am reading this correctly.)

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