Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rebase correctly If my branch has a lot of commits?

My situations looks similar to this this except that my feature branch has a lot more commits

enter image description here

The bug fix which was committed in the meantime also affects my feature branch. This is why I would like to rebase my feature branch to the master.

I tried to do this with git rebase master (being on my feature branch) which ended up in chaos. Due my feature branch has a high count of commits, the rebase takes forever and I keep losing the overview during the rebase process and all its conflicts, with older commits and what so ever.

How would I do this correctly in this situation? What am I doing wrong?

like image 310
Herr Derb Avatar asked Nov 19 '25 11:11

Herr Derb


1 Answers

If you want to rebase your whole history, you will somehow need to re-play each individual commit on top of master, and also do some extra work to keep the sub-feature -> feature merge.

I would suggest to not do that. To integrate bugfix into your feature branch, you could :

  • merge master (with its bugfix) into feature :

    git checkout feature
    git merge master
    

    this would be the most straight forward and git-ish way to do it

  • cherry-pick the bugfix commit onto feature :

    git checkout feature
    git cherry-pick bugFix
    

    it is not the cleanest way to do it, but it certainly works
    later on, you may have to remember that bugFix was present on both branches when merging feature into master, if the you get conflicts on the files modified by bugfix

  • first simplify the history of feature and sub-feature, and rebase the simplified versions on master

like image 79
LeGEC Avatar answered Nov 21 '25 03:11

LeGEC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!