0

my git commit order as below:

commit A ==> commit B(merge master) ==> commit C ==> commit D

the commit B used to pull and merge master, and after that commit C and D used to add/change file. Every commit has been push remote.

However when commit D push remote, the **master rollback **. Then my branch has some code which get from commit B(merge master) and the current master dont have for it has been rollback.

In order to keep consistent with master, I pull and merge master again but make no effect. So is there a way I can remove commit B(merge master)? after that the commit flow look as:

commit A ==> commit C ==> commit D.

Every advice will be great appreciate.

nail fei
  • 2,179
  • 3
  • 16
  • 36

1 Answers1

0

Given that the branch and its merge commit are already pushed to the remote and are public, we should be cautious and avoid rewriting the history of this branch. A safe option would be to revert the merge commit B:

git checkout your_branch
git revert -m 1 <SHA-1 hash of B>

This assumes that you want to follow the first parent of the merge. If not, then use -m 2 instead. You may check git log to verify that the first parent follows back into commit A.

Note that this solution will make a new commit on top of your branch. To push these changes, a normal push will suffice:

git push origin your_branch
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360