2

I had a git repo called chess_assess.

  • I downgraded my local project's Vue from v3.x to v2.x by creating a new local project called chess_assess2 and copying almost all content from chess_assess into it.
  • I then deleted chess_assess and renamed chess_assess2 to chess_assess.
  • Finally, I reset the remote using
    • git remote add origin <path_to_chess_assess.git>
    • git add . && git commit -m ""
    • git push -u origin main

This produced the error

! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/hexaquarks/chess_assess.git'

So I did:

git push -u origin main --force

which worked, but now my GitHub repo commits history is completely gone.

Is there a way to reobtain the commit history of my project while simultaneously connecting this new project to GitHub?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
hexaquark
  • 883
  • 4
  • 16
  • Use the reflog to get the hash of the last commit in the deleted branch and recreate a branch on this commit. – Philippe Sep 27 '21 at 22:07
  • @Philippe `$ git reflog` just shows the last commit I did, that is the commit that overwritten all my previous commits, nothing else. How can I use reflog in the deleted branch when the initial folder `chess_assess` is deleted? – hexaquark Sep 27 '21 at 22:14
  • There is no *easy* way. GitHub have a habit of not actually deleting any commits, though—either for a long time, or perhaps even ever?—so if you contact GitHub support (you may also need to fork over some dollars, I don't know about this part) they may be able to get you your commits back. – torek Sep 27 '21 at 23:02

1 Answers1

1

How can I use reflog in the deleted branch when the initial folder chess_assess is deleted?

You cannot indeed.

If the remote repository remained the same, check its own remote reflog for GitHub, using the GitHub Event API to list push events. I mentioned those here, knowing that public events are delayed by a few minutes.

You might get the last pushed commit, which you can then fetch, bringing with its all its past commits.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250