1

I am working on a feature branch us_stable . I merged another branch Proto in this us_stable branch and after that I did some more commits and pushed to us_stable branch. Now I want to revert the branch which I merged in the begining. In my case I want to revert the changes which was merged in Proto. My Question is:

  • Is it possible to revert that merge? If yes, how?
Shawn
  • 157
  • 1
  • 2
  • 14
  • Since, `Git` uses SHA values to organize commits, so you can not delete an in-between merge. – Arslan Ali May 21 '14 at 09:14
  • There is no any in between merge. I created a myFeature branch and immediately merged another branch in it and then I started to work on myFeature branch and did 3 more commits and pushed to myFeature branch and merged. Now I want to ignore the changes which was merged. – Shawn May 21 '14 at 10:09
  • The scenario you described is exactly what @ArslanAli meant by "in-between" merge. – musicmatze May 21 '14 at 11:05

2 Answers2

0

You can issue the following command:

git rebase master -i

It selects only the commits that you want to have and discards the others.

Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Igal S.
  • 13,146
  • 5
  • 30
  • 48
  • I dont want to rebase myFeature branch. I just want to revert the merge I did in the beginning. – Shawn May 21 '14 at 10:12
  • This answer is absolutely what you want to do. But maybe not on `master` but on the commit you started off your branch from. – musicmatze May 21 '14 at 11:05
0

You can use git reset --hard abcdef123 to move your current branch to the commit abcdef123, for example to the commit just before the merge.

git push --force may be needed to push such branch.

See git help reset and How to undo last commit(s) in Git? for more info.

Community
  • 1
  • 1
Messa
  • 24,321
  • 6
  • 68
  • 92