Home > Software engineering >  Revert a merged pull request
Revert a merged pull request

Time:11-05

I’m working on a project where we have different branches (dev, feature,production). I was working on my feature branch, and did multiple commits on that branch for my changes. Later at some point I took a pull from dev branch and that got merged with my feature branch (which I shouldn’t have done). But, I didn’t realised that mistake at that time, and kept working on my feature branch, and did some more commits.

Now I want to only revert that pull taken from dev and keep all my commits of feature branch, also the one I did after the pull. Is it possible to save those commits? I know a little about Git Reset/revert command, but that will not save my later commits i guess. It will point HEAD to previous commit, before the pull.

Can anyone help how I can save my commits made after that merge? Or my understanding isn’t correct regarding Reset\Revert command?

Note-: Changes are already committed and pushed on remote.I’m using Source Tree.

CodePudding user response:

  1. In Sourcetree, double click the last commit before the merge. Doing so will make your working copy a 'detached HEAD' etc

  2. Click "New Branch" and give it a name.

  3. Navigate to all the commits you did after the merge, right-click them and choose "Cherry Pick"

CodePudding user response:

You just have to reset your checked out branch (with git reset --hard) to the point you want it to be. You may have to use git reflog if the point you desire has been lost.

Until people don't realize, a bad usage of git can lead to developers losing their changes. It is convenient to backup changes using local mirrors sometimes.

  • Related