0

I am a Git novice and totally messed up my remote master branch. I had a branch (add-comments-model) which I merged to master (and actually pushed it) and regret it. Now I would like to undo all these but the merge was done on command line instead.

My Git log of master looks like this:

111  Merge branch 'add-comments-model'
222  Merge branch 'master' into 'add-comments-model'
333  Merge pull request #24 from good-merge
444  some commits from add-comments-model
.
.
666  some commits from add-comments-model

Ideally I hope to return to commit 333 ( a merge commit ) but i notice that the Merge branch 'master' into 'add-comments-model' must have caused some of the commits from add-comments-model to seep into the master branch log?

Can someone advise me on how to get my master branch back to commit 333?

kelvintaywl
  • 215
  • 2
  • 9
  • Check out the answers here: http://stackoverflow.com/questions/2389361/undo-a-git-merge I suggest avoiding the most popular answer there. Instead look at the one with "git revert -m 1 commit_hash". – V Maharajh Nov 08 '14 at 06:47

1 Answers1

0

Locally:
git reset --hard 333
git push --force origin master

Mauricio Trajano
  • 2,677
  • 2
  • 20
  • 25
  • thanks for answering. Would `git push --force origin master` affect other team members? also, would that remove the 444 and 666 commits? – kelvintaywl Nov 08 '14 at 05:55
  • It will affect the remote repository, so as long as they do a pull they will have the same thing as you. It will not delete older commits, only the ones that come after 333 – Mauricio Trajano Nov 08 '14 at 05:57
  • @user3673335 If they would have already done a pull, then they will have conflicts I guess. – Anshul Goyal Nov 08 '14 at 06:15
  • You don't want to force push to a branch that is shared. It is considered impolite. It'll earn you a bad name amongst your peers. If your teammates are also new to git, it'll confuse them all. – V Maharajh Nov 08 '14 at 06:44
  • hi all thanks for the help! i really appreciate it. however, I found out that if i choose to do a `git revert -m` command, when I make a pull request for the 'add-comments' branch, github shows no file changes. I believe the git history is not erased with git revert? My next question is thus: if I choose to git revert, and push my branch for Pull Request once more, how can I make sure the file changes show up? – kelvintaywl Nov 09 '14 at 02:29