0

I made a mistake when using git:

#In master, which has commits like a-b-c#
git push origin master
git checkout -b branch2
# Now I'm in the branch2, and I did:
git reset --hard a
# work...
git commit ...
# work...
git commit ...
# so, now I have commits in branch2: a-d-e

If I go back to master and merge branch2, it will be something like a-b-c-d-e. However, any thing in commits b and c are completely garbage that I don't want.

How can I make remote repo to be a-d-e? (The remote's master already has a-b-c since I did a push before branching to branch2) I really don't want to mess up the repo, will git push origin master --force be a good option?

Edit: After goolging git revert, I found this question worth reading

Community
  • 1
  • 1
GuLearn
  • 1,814
  • 2
  • 18
  • 32
  • It depends on whether anyone else may have seen the remote branch. See, for example, [this question](http://stackoverflow.com/q/13073230/212858). – Useless May 23 '13 at 13:07

1 Answers1

1

git push origin master --force would rewrite the history as you intend. However, if there are other developers pulling from the repo it will cause them trouble.

As a rule if you have pushed the commits rather than rewriting history you should do git revert <sha> This will make a new commit reversing the changes of the sha provided. This doesn't erase the problem from the history, but will cause the least amount of trouble.

Schleis
  • 41,516
  • 7
  • 68
  • 87
  • You made my day!!! `revert` is EXACTLY what I want! I hope I can upvote you twice, then accept your answer twice – GuLearn May 23 '13 at 13:19