Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to merge all commits except one

Tags:

git

git-merge

We are using more or less git flow as our workflow. We have a bunch of commits in acceptance. We need to release most commits from acceptance to master right now, but there is one that still needs the acceptance from business side and we will have to wait for another deploy window.

Example of commits to merge:

12345
54321 <- don't want to merge this just yet
78945
54789

So I want to merge acceptance -> master but avoid merging 54321.

Whats the best option I have here? Revert? Cherry pick a range of commits? I don't like both this approaches, is there something else?

like image 642
Pedro Costa Avatar asked Jan 18 '26 15:01

Pedro Costa


1 Answers

  1. Assuming you are on the acceptance branch, do a interactive rebase and swap the last two commits.

    git rebase -i HEAD~2
    

    In the editor, swap commit 12345 and 54321. The result should look something like this:

    pick 12345 ...
    pick 54321 ...
    

    Save and close the editor.

  2. Merge the second last commit from the acceptance branch into master.

    git checkout master
    git merge acceptance~1
    

    Before:

     54789 - 78945 - 54321 - 12345 (acceptance)
      /
    11111 - 22222 (master)
    

    After:

     54789 - 78945 - 12345 - 54321 (acceptance)
      /                \
    11111 - 22222 --- 33333 (master)
    
like image 108
sergej Avatar answered Jan 21 '26 07:01

sergej



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!