0

Here is my current situation. I merged a branch into my live branch and pushed it to the remote repository. But, there was an issue with code on that branch. I want to revert this live back to a previous commit which happens to be another merge into the live branch. How would I do this?

I don't quite understand the difference between git revert reset and rebase, and am not sure which of any of these is appropriate in this case.

  • you can use `git revert` check this [git-revert](https://www.atlassian.com/git/tutorials/undoing-changes/git-revert) – ROOT Mar 19 '20 at 04:53
  • I tried this - I ran `git revert merge-where-I-messed-up` and I got the error `is a merge but no -m option was given.` – BlobbityBloop Mar 19 '20 at 04:57
  • its asking for a commit message, just add `-m "COMMIT_MESSAGE" ` replace COMMIT_MESSAGE with a text message for the commit since reverting change will be considered as a new commit in your git history. – ROOT Mar 19 '20 at 05:00
  • I tried to run `git revert 1a2b3c -m "Revert to before issue"` but I get the error `error: switch `m' expects a numerical value` – BlobbityBloop Mar 19 '20 at 05:03
  • Might be a silly question - but should I be reverting to commit where error occurred, or merge before error occurred? – BlobbityBloop Mar 19 '20 at 05:03
  • sorry my bad -m option asks for parent commit, check [here](https://git-scm.com/docs/git-revert), try to use `-m 1` this will revert to one previous commit. – ROOT Mar 19 '20 at 05:08
  • @Ma'mounothman Thank you! That did the trick – BlobbityBloop Mar 19 '20 at 05:24
  • Gald to help, I will add it as answer, just incase someone need it! – ROOT Mar 19 '20 at 05:25
  • Does this answer your question? [git revert not allowed due to a merge but no -m option was given](https://stackoverflow.com/questions/24301390/git-revert-hash-not-allowed-due-to-a-merge-but-no-m-option-was-given) – phd Mar 19 '20 at 08:55
  • https://stackoverflow.com/search?q=%5Bgit-revert%5D+merge+but+no+%22-m%22+option+was+given – phd Mar 19 '20 at 08:55

2 Answers2

0

don't quite understand the difference between git revert reset and rebase

Well you could use any of them. But because you already pushed, using revert is the only "nice" way of doing it if you have other people working on the same repo.

As for how to apply the revert:

git revert -m 1 <merge commit hash>

Note you need the -m option because, merge commits are essentially commits with pointers to 2 parent commits and:

"Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent."

https://git-scm.com/docs/git-revert#Documentation/git-revert.txt

marblewraith
  • 768
  • 5
  • 16
0

to revert a change you made, you can use git-revert

you can use revert like this:

git revert -m 1

the number 1 represent the number of commits you want to revert.

ROOT
  • 11,363
  • 5
  • 30
  • 45