Few weeks ago in one of my projects I merged а branch into master. Later I realize that the branch I merged into master has changes that I don't want to be in master. Is it possible to revert the changes in master made by this branch?
Asked
Active
Viewed 262 times
-1
-
You can reset master's HEAD to the previous commit. -- I would advise against revert in this case. – evolutionxbox Dec 08 '17 at 11:10
-
May be helpful: https://stackoverflow.com/q/16174629/2759108 – SharpKnight Dec 08 '17 at 21:41
-
downvoting because duplicate and no visible effort of searching for an answer first. – tkruse Dec 09 '17 at 15:58
-
@MZON Can you revert the changes successful now? – Marina Liu Dec 15 '17 at 09:21
1 Answers
0
Yes, it’s possible. You just need to execute git revert <commit>
on master
branch.
Assume your commit history as below for now:
A---B---C mybranch
/ \
D---E---F---G---H master
If you want to revert the changes from commit B
by mybranch
, you can use the command:
# On master branch
git revert <commit id for B>
Then the commit history will be:
A---B---C mybranch
/ \
D---E---F---G---H---B' master
Note: if there has conflict during the revert, you can modify and save the conflict file(s), and then use git add .
and git revert --continue
to finish the revert.

Marina Liu
- 36,876
- 5
- 61
- 74