Question

The situation: Bob merged his development branch BranchA into master (commit hash [c1]), then performed another commit on master (commit hash [c2]) to tweak something and remove some debug lines he forgot about. Then a few more commits are performed on master afterward (hashes [c3] and [c4]), that don’t touch any of the same code that [c1] and [c2] did.

Well, Bob didn't actually have permission to make those changes, and we now want to back them (both) out of master.

If we do git revert -m 1 [c1], it gives this error:

error: could not revert [c1]... Merged in BranchA (pull request #398)
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

So, how should we go about correctly removing that code? As a note, we would still like to keep commits [c3] and [c4] in our codebase -- we just need the merge that happened [c1] and the commit at [c2] taken back out.

Était-ce utile?

La solution

Rebase your Head~4 (because there were 4 commits - just use as many numbers as you want to go back). Then remove c1 and c2 while rebasing.

Some documentation on that: http://git-scm.com/book/en/Git-Branching-Rebasing

Just now, I also found this relevant question here in SO: Delete commits from a branch in Git

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top