-1

I copied a project and edited it to create a new project. I made a lot of changes. After 3 months, I tried to push to the repository.

  1. Pushed to the older repository. (All code was fine and complete.)

  2. git reset --hard HEAD^ git push origin -f these were implemented to the older repository. (It removed the last commit from GitHub but I didn’t noticed it removed from local as well.)

  3. Deleted .git folder. Then created new repository and pushed code to that new repository.

As I said I didn’t noticed local data was also changed. That changed data was pushed to the new repository.

I lost my important data of 3 months.

Alot of blogs and answers suggested to use

git reflog show

as git was removed from project and new repository was linked. The older repository was cloned and implemented this command but didn’t showed any changes or HEADs.

git fsck --lost-found

I tried this one as well but didn’t worked.

.git folder deleted from the older project was also removed from trash.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 1
    Just for clarity, what's the aim here? Is it to restore your code back to before step 1? – Shaun Phillips Dec 13 '22 at 17:27
  • 2
    Once you removed `.git`, there is not much you can do to get information anywhere **if it was not pushed or pulled** into another repo. – eftshift0 Dec 13 '22 at 17:37
  • Perhaps the IDE can help you get information from its local history. – eftshift0 Dec 13 '22 at 17:38
  • 4
    Your only hope here is that at some point you pushed the full version of history to Github (is that what you mean by step 1?), and there's still a copy there somewhere. If you can't see it, maybe try contacting Github support, who might be able to locate orphaned revisions that are still on their server. Otherwise, this is less about git, and more about attempting to retrieve deleted data from your hard disk. – IMSoP Dec 13 '22 at 17:45
  • 4
    If you pushed the desired commit to GitHub, and then force pushed the reset afterwards, the desired commit may still be there. See [this question](https://stackoverflow.com/q/68851451/184546) for 2 ideas, which are basically try the remote reflog API, or contact GitHub support. – TTT Dec 13 '22 at 19:36

1 Answers1

1

Thank you everyone. as @imsop and @ttt suggested if code was pushed on GitHub so the copy may exist somewhere on GitHub. I contacted GitHub support and they applied reflog on their server and found that commit.

  • 1
    Glad you were able to get your data back. For the future, if you're ever not 100% certain of what you're doing with git, it's fast and easy to make a backup copy of your work by just creating a new branch: `git branch backup-branch`. – Caleb Dec 16 '22 at 05:49
  • @Caleb thank you that's helpful. – Muhammad Owais Dec 16 '22 at 15:52