0

This question has been asked too many times but I am not finding solution to my situation, and so will ask it again. I have 2 branches - master and residents. I have been working on residents for about 2 months, basically a complete redesign of a form (tons of check_boxes, radio_buttons etc. to avoid typing). Approximately 35 commits. Couple of times or so I have done minor changes in the master and merged the master into the residents. Then when I was happy with the residents, I switched to the master, merged the residents into it and pushed to heroku.

The app (actually, the form containing some JS) doesn't work on heroku (it does on my local). I rolled back on heroku, and now I need to return the app to the state before the merge and push. I have the residents branch, so all I need is to discard the entire merge from the master.

I think this should be an easy undo, but I didn't find out how.

Thanks for help.

Arta
  • 5,127
  • 5
  • 25
  • 23

2 Answers2

0

I think you can reset merge then push again.

git reset --merge : Resets the index and updates the files in the working tree that are different between and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between and the index has unstaged changes, reset is aborted.

http://git-scm.com/docs/git-reset

Pattapong J
  • 1,204
  • 12
  • 21
0

Assuming that the most recent commit in master is the merge of your resident branch, and that you aren't sharing your app with others, you can do:

git reset --hard HEAD~1

That command says to rollback to the previous parent. Then you'll need to do:

git push --force

You can also use git revert to do this, but that comes with some extra complexities of it's own too. You would have to revert the merge commit, and later, when you want to bring the branch over, you would revert your revert, and then merge the branch. Otherwise, all the revisions won't come over. I favor the history modification in this case, which is what I showed you above, because it's simpler and more clean when you can get by with it.

John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
  • I ran $ git reset --hard [SHA of the last commit done in the residents, merged into the master] after I found out the app was not running on heroku. I thought that was the undo I was looking for. It did not undo the merge at all. It discarded the last commit (of the 35 or so that were done on the residents and merged into the master). So, at this moment my master is nearly identical to the residents, it differs from the residents only by the last commit (which was undone by the above). I need to get rid of all of the commits done in the residents and merged into the master. – Arta Nov 20 '12 at 14:53
  • I'm not sure I'm parsing your first sentence correctly, or maybe there is an error there. You want to `git reset --hard` to the commit you want to rewind to. If the merge was a fast-forward merge, then those are harder to revert because the history looks as though it was developed all on the master branch. Did you have a tag for the previous version? Do you know the SHA1 for the last version of master? If so, use that for `git reset --hard` on master. – John Szakmeister Nov 20 '12 at 15:46
  • Yep, we had a misunderstanding. It looked like you meant "HEAD~1" literally. Yes, I know SHA1 of all of the versions ($ git log). I wanted to avoid reseting --hard to a particular SHA1 since I thought I'd loose track of the few commits made in the master and merged into the residents (they would have to be "transferred" back into the master manually?). I did not have any tag. Something to learn to use? Would it help now had I had a tag? Is there a way to restore the repo to its state before the merge? This is something I thought would be simple, that's why I went ahead with the merge. – Arta Nov 20 '12 at 17:15
  • Yeah, it should be easy, but in the face of fast-forward merges, things can get more difficult. One thing you can look at is the [reflog](http://git-scm.com/docs/git-reflog) on master. It shows you the values HEAD has taken on. If you can find where the merge to master happened, then you can find which commit master was at and be sure that you haven't lost anything. `git reflog` can be a bit hard to read, but the information you need is in there. Here's a [useful reference on reflog](http://git-scm.com/book/ch6-1.html#RefLog-Shortnames) as well. – John Szakmeister Nov 20 '12 at 18:33
  • One more thing. You can consider doing merges with `--no-ff` so that there is always a merge commit present. You can also set merge.ff to false. You can set it globally with `git config merge.ff false`. – John Szakmeister Nov 20 '12 at 18:37