0

I accidentally reverted a commit that was unrelated to my my work from my local feature branch. I have pushed my changes up to my feature branch and was about to issue a pull request to have my code reviewed and I can see that there are a whole load of unrelated changes which are due to the revert I did.

I can see the id of the commit that I reverted in BitBucket and just want to know what the easiest way is to undo the revert and pull the commit back into my branch.

I could take a new branch from development and then go through the process of manually merging my actual changes back into the new feature branch, but I suspect there is a much simpler action.

Just for reference, all of the fetch, pull and push are done through GIT Extensions.

2 Answers 2

3

When you do a git revert another commit is created, revert the revert commit.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you do this even though I have pushed the changes to the remote branch and have been committing and pushing changes since I accidentally did the revert?
Yes you can still find the commit and revert it.
0

Simple just reset to that commit.

git reset --hard <commit_id> 

Or

git cherry-pick <commit_id> # If you have other commits over it 

4 Comments

That would only work if they haven't continued to work on top of the branch after the revert.
I have continued to work on the branch after I did the revert.
So just follow the second solution and cherry pick the single commit.
Ok. git cherry-pick looks like it could be the savior. Just one question. If I take the colleagues commit from the origin/develop branch which is our master dev branch for the whole project when I then push the changes to my origin/feature branch will git detect that the changes are not already on dev and therefore ignore them?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.