0

I made a mistake I ran these commands then my projects become empty. Is there a way I can restore a very important one?

rm -rf .git
git init
git add.
git commit -m "Initial commit"
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
git push -u --force origin master

I did find a backup but all of the files contains null null values:

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 1
    Clone your repo from the remote again. If there is no remote, you've just deleted your entire repo ‍♂️ (the rabbit-hole of `undo rm -rf` is one that is deep and perilous) – Adam Smooch Sep 25 '21 at 13:09
  • i did clone but all i get is .idea and .mvn also i did back up and get the files but very file contains null null value – rust dexter Sep 25 '21 at 19:04
  • The missing commits may be in the remote repository still, if they weren't garbage-collected yet. – Ulrich Eckhardt Sep 25 '21 at 20:08
  • 1
    If what you found in the backup is the .git directory, then you shouldn't expect to be able to read them yourself - they are a database that git reads as it needs to. Try restoring the whole directory and seeing if git can read it, e.g. running "git status" – IMSoP Sep 25 '21 at 21:09
  • 2
    The short answer is no: you did not just remove the files, you also removed the entire Git database. Then you made a new, empty Git database (with nothing in it) and told the remote server to overwrite its Git database with the empty one. You need to find data saved from before these events. The remote reflog trick *may* work, if the remote has reflogs; you mention github.com and they don't actually delete stuff, but it's not easy to get either. You could consider contacting GitHub support and see if they will recover your data for you: they probably can do this, although it may cost $. – torek Sep 25 '21 at 21:35
  • @IMSoP yes there is the whole directory also with .git directory – rust dexter Sep 26 '21 at 00:30
  • @torek the remote reflog doasn't work i contacted the support I hope they can help me very important project I will be in trouble if a lost it – rust dexter Sep 26 '21 at 00:31

1 Answers1

0
git push -u --force origin master

after that you need to consult git reflog. All commits on the remote are still present, and you can see it with git reflog. you will have to reset your master to the commitHASH that was before you ran --force.

also have a look at : git can I view the reflog of a remote?

As mentioned above garbage collection may take place, then things will get lost

Dmitry
  • 353
  • 2
  • 8