0

I know there're already lots of questions like that but nevertheless, if possible, I would prefer to double check if I'm doing it right cos the last thing I want is a messed up commit tree. I accidentally merged the so called stage branch into my task branch and pushed it to the remote. These are the latest commits on my task branch:

commit 0b7215203eb10cb11bba94147b170ca51a45e8b2 (HEAD -> ISSUE-1771, origin/ISSUE-1771, stage)
Merge: 87f0fc3 d3e6f17
Author: AUTHOR
Date:   DATE

    Merge branch 'stage' of PATH_TO_PROJECT into ISSUE-1771

commit 87f0fc31b94b68e10d3b49a19facf4474a1799d6
Author: AUTHOR
Date:   DATE
        COMMIT_MESSAGE

Now I would like to revert the commit and I'm going to do this in the following way:

$ git checkout ISSUE-1771 && git revert 87f0fc3 -m 1

which, unless I'm very much mistaken, is supposed to revert the tree back to what it was in 87f0fc3.

So after I do the reversion I'm going to push to the remote task branch like so:

$ git push origin ISSUE-1771

then checkout stage and pull the changes from the ISSUE-1771 branch, it will merge them into stage and then push to the remote stage.

So it should go like this:

$ git push origin ISSUE-1771

$ git checkout stage && git pull origin ISSUE-1771

$ git push origin stage

Is this correct?

GoBear
  • 518
  • 1
  • 5
  • 19
  • `$ git checkout ISSUE-1771 && git revert 87f0fc3 -m 1` will **not** revert the tree back to what it was in `87f0fc3`. It will introduce at the tip of the current branch a commit containing the reverse changes that `87f0fc3` introduced. If this is the last commit, yes, it will result in the same tree state you had just before, but don't you confuse `revert` with `reset`, it might be deadly. – Romain Valeri Feb 27 '19 at 10:06
  • Also, you're giving the `-m` parameter to `revert` as is expected when one reverts a merge commit, except... the commit you're reverting is not a merge commit. `0b72152` is a merge commit. – Romain Valeri Feb 27 '19 at 10:09
  • @RomainValeri Ow yeah I see, I'm reverting the wrong commit, so everything seems right except the revert command should look like so `git revert 0b72152 -m 1`. Right? – GoBear Feb 27 '19 at 10:22
  • 2
    I refrained from actually answering because there are many sub-questions to be asked before one can fully judge the situation. Do you have the opportunity to rewrite history on that branch? If so I wouldn't have reverted the bad merge, it's only cluttering the history of the branch for nothing. If not, then yes `revert` is the way to go. However, it would be a bit uncommon for a feature branch on which you probably are alone, unlike the stage branch. – Romain Valeri Feb 27 '19 at 10:43
  • check this https://stackoverflow.com/questions/22682870/git-undo-pushed-commits – jo_ Feb 27 '19 at 14:30
  • I think you should start by creating a new branch on head , then try all kinds of things you want to try and carefully check if result is what you expect if not so start again a new branch and try again. Creating a branch to try something is cost less and kind of gives you a new play ground to try and learn. – jo_ Feb 27 '19 at 14:35

0 Answers0