1

Today happened to us something embarrassing at work and a new partner has made a commit & push and has overridden everything that was in the repository.

Now I need to get back to the point where we were before the disaster.

You can delete commits to the remote repository?

If not, as I can put a commit (for example: 0231c10) as Head of the master branch?

pfnuesel
  • 14,093
  • 14
  • 58
  • 71
Borja Pombo
  • 525
  • 1
  • 7
  • 30
  • Literaly you have a big problem now. Following solution I'd like to suggest. If you still havent pushed or pulles to/from the 'disaster' repo. You/some is in the good position to still have the 'correct' repository. So you can delete the remote completly, create a new empty repo and push your correct repo to the new remote. – ckruczek Jan 22 '16 at 17:25
  • Possible duplicate of [Revert Git repo to a previous commit](http://stackoverflow.com/questions/4114095/revert-git-repo-to-a-previous-commit) – Ferrybig Jan 22 '16 at 17:34
  • If force push is enabled in that remote repository, then it may be better to check that the push wasn't a `push -f`. – J.J. Hakala Jan 22 '16 at 17:40
  • If you have your branch in the good state in your repository, do a force push. – Philippe Jan 22 '16 at 21:01

3 Answers3

0

You can do it with git reset --hard 0231c10 while you are on the master branch.

Borys Serebrov
  • 15,636
  • 2
  • 38
  • 54
0

If overriding of repository was done using one new commit, then it's better to revert it using command git revert <hash>. With reverting will be created new commit and it will just revert changes made in commit <hash>.

Using such approach you will still have wrong commit in your history, but if you don't have enough experience it is best way to fix such problem, just because it is easy, otherwise with approach like git reset --hard 0231c10 you will need to use push with force option and it's not very safe action and even if you are ready to go on this risk you need to know that you will need to ask all committers to do not very safe actions on their environment, like this git fetch origin and then in master branch git reset --hard origin/master.

But if you think you are ready for rewriting history in your repository then use git reset --hard 0231c10 as was proposed in another answer.

Ivan M.
  • 164
  • 1
  • 1
  • 4
0

Usually, in published repos, it's safer to do git revert and then git push. There are other solutions too,

  1. Without doing any changes to your local repo, you can also do something like git push -f origin 0231c10:master

  2. git reset --hard <revision_id_of_last_known_good_commit> and git push --force

Msp
  • 2,493
  • 2
  • 20
  • 34