0

I have a master branch and a feature branch.

I have some commits in feature branch, and I cherry-picked them to master branch.

So, now my master branch contains those commits already. I noticed then I shouldn't do those cherry-picks.

Now, how can I revert my master branch back to the status before cherry-pick?

Leem.fin
  • 40,781
  • 83
  • 202
  • 354

1 Answers1

0

If you didn't push the bad changes to remote yet:

git checkout master
git reset --hard <commit_before_bad_changes>

If you did push the bad changes to remote already:

git checkout master
git revert <bad_commit_1>
git revert <bad_commit_2>
git revert <bad_commit_3>

Revert will not remove the bad commits from the history but create new commits which remove the content of the bad commits.

Martin G
  • 17,357
  • 9
  • 82
  • 98
  • the reverts should be in reverse order (revert the last one first) to avoid conflicts; `git reset --hard origin/master` is IMO preferable (same as your first suggestion, just likely easier to understand/remember). – AD7six Apr 03 '17 at 10:18