There is a working repository with a long history. The programmer accidentally executed git init in it and sent it to the server. As a result, a bunch of garbage was recorded, the rights to the files changed + everything else. An init commit cannot just be canceled ( revert ). How all the same to cancel it and return everything back?

1 answer 1

Attention! Very dangerous commands are described, potentially destructive. It is recommended to follow them with caution. Remember to make a backup just in case.

  1. Read the entries in the reflog. git reflog

  2. Make git reset --hard HEAD@{N} where N is the desired commit

  3. Check that the current point is exactly the one you need.

  4. If you are satisfied with the state, then make git push -f (since you managed to send to the server)

  • four
    For insurance, you can leave a backup branch on the current final commit. And to do it better after you pull , and warn all your colleagues so that they don’t throw anything in the repository. - D-side
  • git init in the already initiated repository should not do anything at all. Explain, please, what happened to the author? - Nick Volynkin