Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

is there a way to undo/revert a revert?

Elias Aseged June 15, 2018

Yes, you read that correctly :). Hope this makes sense, so here's what happened:

 

I merged my working branch into master, per usual. My internet dropped midway through the merge and my local/working branch corrupted (workspace integrity issues). As I was trying to debug and figure out how to fix, I came across the "Revert" button on Bitbucket. So, I clicked it to see if that would solve my problem.

What I saw was that it would create a new PR "called revert pr #" which looks like it selects the previous commit (or undos the most previous commit) and merges that back into master. logically, that's fine and worked as it should.

however, I realized that actually didn't solve my workspace integrity issue, and I had to do some other stuff to fix that. once I fixed the workspace issue, I wanted to re-try merging the original PR (PR #53), but it still says "revert". I suspect that this doesn't actually "revert my revert" and instead repeats the process of creating a new PR, etc.  Screen Shot 2018-06-15 at 6.56.28 AM.png

so rather than trying that, i tried to go back to the branch that the original PR was created for and create another PR for it. but, it's not working. despite the working branch being different from the master, it doesn't seem to let me create a new PR as it said something to the effect of "there are no changes in this branch from the master branch". so i artificially forced those changes by deleting a few comments, etc., hoping that would do something to no avail.

 

so now, I'm trying to figure out how to revert back my master to pre PR#53 being merged and also recreating PR #53 so that I can merge in the working branch into my master.

 

I hope that makes sense?

2 answers

2 votes
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 15, 2018

Hi Elias,

It is possible to have you changes added back to your master branch, but there are a couple of things you need to do.

Linus Torvalds explains the situation (https://mirrors.edge.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt):

Reverting a regular commit just effectively undoes what that commit did, and is fairly straightforward. But reverting a merge commit also undoes the _data_ that the commit changed, but it does absolutely nothing to the effects on _history_ that the merge had.

So the merge will still exist, and it will still be seen as joining the two branches together, and future merges will see that merge as the last shared state - and the revert that reverted the merge brought in will not affect that at all.

So a "revert" undoes the data changes, but it's very much _not_ an "undo" in the sense that it doesn't undo the effects of a commit on the repository history.

So if you think of "revert" as "undo", then you're going to always miss this part of reverts. Yes, it undoes the data, but no, it doesn't undo history.

So in order to get your changes back into master, you need to do this:

  1. Checkout the branch you want to merge back
  2. Create a new branch that will be used to replay your commits made on the original branch
  3. Locate the parent commit from which your original branch was created from, you can use git log --graph --oneline --all to find it
  4. Run git rebase --no-ff <parent commit from above> to rebase your new branch to replay your commits.
  5. Merge your new branch into master via a pull request.
Elias Aseged June 15, 2018

Hi Mikael - Thanks for the response.

I followed the steps you outlined, but as I'm trying to merge the newly created branch (SAP107v2) that I created from my original branch (SAP107) into master via the PR, it's still not reading the changes.

So in both SAP107 & SAP107V2, there are 3 files that I changed. And master (both remote and local working) don't have these changes (obviously), yet the PR isn't seeing the difference beyond a line that i commented out to force a new commit.

What am I doing something wrong? I almost feel like I should just "force push" this SAP107 or SAP107V2 to master and overwrite it since technically it has everything that I need.

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 15, 2018

It almost sounds like the new branch was not rebased correctly. A force push should do it too.

elninjagaiden February 18, 2019

EDIT (wrong place to put mi initial question):

 

Hello, how exactly do you find the parent commit from where you branch was created?

I run the commando but I don't know how to interpretate the output

Igor Pezzini January 29, 2021

Mikael, thanks a bunch for this solution.

I am in the same situation 2.5 years later and it seems that the --no-ff option was deprecated and removed from git in the meantime. I find no trace of it anymore. I will try to figure it out on my own, but if you have any Idea I appreciate every input.

Kind regards

Igor

0 votes
elninjagaiden February 18, 2019

Hello, how exactly do you find the parent commit from where you branch was created?

I run the commando but I don't know how to interpretate the output

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 19, 2019

@elninjagaiden you basically have to follow the lines in the output and try and figure out which of the commits is the parent one. If you only have one commit on the branch it is simple, if you have many it will take some detective work. Example:

Lets say I want to find the parent commit for bugfix/SB-60-user-scenarios-demo. If you do it from the command line, you can see it is not that easy to find it. The top screenshot is from within Sourcetree and it makes it easier to find the parent.

tree.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events