简体   繁体   中英

How to restore files after double git init command in Visual Studio

I decided to make git repository with Visual Studio and added version control using VS tools. I have never do that, so I thought I should make repository myself and VS will only make .git and add some gitignore lines.

My project contained some files which are dangerous to keep public but when git was initialized in VS there was first commit including my file.

  1. Then I added this file to gitignore and done one more commit.
  2. Then I realized that this file still is accessible if I publish changes. So, I tried to delete first commits in VS but I did not understand how(Though, I did that, I clicked several times on revert button but nothing happend).
  3. Then I just opened command line and typed in git init . I saw Reinitialized existing Git repository in D:/Projects/Programing projects/C C++/QT/SushiWokAdmin/MY_GREAT_PROJECT_I_WAS_MAKING_IT_FOR SEVERAL_WEEKS/.git/ .
  4. Then I went back to VS and saw that project was closed.
  5. Then I went to my project folder I saw that all my files are gone, except those, that was in gitignore file.

I have not done any commits nor pushes . How can I restore my files?

PS: I still have .vs folder with some files in it, can this help me to restore my project?

Running git-init didn't delete your files.

git-init documentation :

Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates.

Your files might still be there in the repo.

You can try:

  1. Restore from the index: git restore :/
  2. Reset the files from the current commit: git reset --hard
  3. Check other branches and the history ( git log --graph --all --oneline )
  4. Follow Data Recovery from Pro Git to restore data from deleted commits and the object database.

I really needed those files. So only R-Studio helped me. I just searched for deleted files and recover what I could :(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM