Pedro Costa
Pedro Costa

Reputation: 195

Best way to merge all commits except one

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?

Upvotes: 3

Views: 1073

Answers (1)

sergej
sergej

Reputation: 17999

  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)
    

Upvotes: 2

Related Questions