1

We have a PR everything it's ok, except 1 commit, it is possible to just merge everything except a specific commit?

2
  • 4
    Revert that commit in branch then do the merge. Works for you?
    – Sangharsh
    Feb 9, 2017 at 18:07
  • Another option is to reject the PR and ask for a new PR without that commit.
    – ElpieKay
    Feb 10, 2017 at 3:04

2 Answers 2

3

If the commit you want to skip is the last commit in the branch, you can just merge its parent.

branch ...   A --- B --- C
            /       \
master ... O   ...   git merge branch^

If it's not, you can git cherry-pick each commit aside from the bad one. A shortcut for this is to use git rebase -i and delete the line you don't want.

branch ...   A --- B --- C
            /
master ... O ...

$ git rebase -i master branch
(inside editor)
pick 0123456789 A  (delete this line)
pick 3456789abc B
pick 6789abcdef C
(save and exit)

branch ...        B' --- C'
                 /
master ... O ...

You could also merge and then revert the commit.

$ git merge branch
$ git revert A

branch ...   A --- B --- C
            /             \
master ... O      ...      merge --- ∀

Or revert in the branch and then merge.

$ git checkout branch
$ git revert A
$ git checkout master
$ git merge branch

branch ...   A --- B --- C --- ∀
            /                   \
master ... O         ...         merge
1

You can merge the branch in the working tree, and revert the unwanted commit before committing.

git merge --no-commit branch
git revert --no-commit unwanted_commit
git commit -m "Merged branch (except unwanted_commit)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.