Can deleted .git be restored?

后端 未结 4 2127
刺人心
刺人心 2020-11-27 19:40

This happened when working with git on Ruby on Rails. several commits and branches were done and created.

git version 1.7.3.4

I accidentall

相关标签:
4条回答
  • 2020-11-27 19:50

    The only way you can restore a deleted .git folder is by:

    • Cloning it again from somewhere
    • Checking your recycling bin or backup (if no remote repository exists)

    Since your files are from the online github repository, then its simple. Just clone it again from the directory where you deleted the .git folder:

    git init
    git remote add origin <repo_address>
    git pull origin master
    

    where repo_address can be git@github.com:yourname/yourproject.git

    Your local checkout will be back to normal.

    If you have uncommitted changes in your working copy you would want to keep, instead of using git pull use git fetch and then git reset --soft your local branch to the remote branch it should be at. The soft reset will not change your working copy

    0 讨论(0)
  • 2020-11-27 19:54

    I think the best bet is to Clone the repo in a throwaway folder. And copy the .git folder from that to your desired folder location (The project folder in which you've deleted .git folder).

    0 讨论(0)
  • 2020-11-27 20:05

    You can clone your repository to another location and simply copy the cloned .git folder to the place of your deleted .git folder.

    0 讨论(0)
  • 2020-11-27 20:06

    if you compiled your work and it is in a jar format. Go to your .m2/repository/location and find that jar file. change the .jar to .zip. unzip the file and your git repository should be there.

    0 讨论(0)
提交回复
热议问题