1

I had a git repository and for some reason I want to do these things:

  1. delete remote repository (repo)
  2. From the existing directory (which was earlier corresponds to the deleted remote repo), I would like to create a new git repo.

So, to perform this I did following:

  1. Deleted old remote repository
  2. Created a new remote repository, and
  3. Finally, run the following set of commands:
rm -rf .git
git init
ls -a
git add *
git pull git@github.com:arunhep/DYAnalysis.git master
git commit -m "first commit"
git remote add origin git@github.com:arunhep/DYAnalysis.git
git status -s
git status
git push

But at the end what do I see is that there is nothing on the github.com nor in my present working directory. Somehow I lost all the codes.

One more thing I noticed that I added few thing like *.so, *.pyc, *.pdf, etc in the .gitignore file. So, all these files are there but not the actual files like *.C, *.py, etc.

What I did wrong so that this happened? and Is there any way to recover all the lost files?

[Update] I found how to recover all the files at link:

git deleted everything, how to recover files and folders

But, still not able to get why this happened?

ramkrishna
  • 632
  • 1
  • 7
  • 24
  • 1
    Hey I just repeated all of your steps above and I did not have this problem. Could you please provide some more information on your environment or maybe any missing commands? – WilliamComputerScience Aug 10 '16 at 16:27
  • Do `git init` and then after it run `git clone `. Let us know what happens – e.doroskevic Aug 10 '16 at 16:31
  • @e.doroskevic In the same directory where I performed all the commands that I wrote in question? – ramkrishna Aug 10 '16 at 16:37
  • Yes, please. Also, if there is nothing in your **Git Hub** - does it mean you also deleted the remote repository while you were at it? :s If you did, there is probably nothing to *clone* or *pull* – e.doroskevic Aug 10 '16 at 16:40
  • @e.doroskevic : 1. But, as I know git init initialize the git repo and my pwd is already initialized with this. 2. git clone git@github.com:arunhep/DYAnalysis.git will create a new directory named DYAnalysis inside my git repo. So, is there any specific reason for these commands? No, new remote repository is there as it was with its README.md file as it was when I created it. Also, As I again added my code from somewhere else to this directory and run the commands git add , git commit -m "message", and git push. So, after this it uploaded that file. – ramkrishna Aug 10 '16 at 16:43
  • @e.doroskevic Also you can look commit history here: https://github.com/arunhep/DYAnalysis/commits/75eaeb1c178b735b343896ecfe9d61afe1960fb9 But, before 2nd commit I lost all my files while doing the steps that I mentioned in my question. – ramkrishna Aug 10 '16 at 16:48
  • @ramkrishna what did you actually lose? Your `initial commit` has a single file in it *readme.md* and your `first commit` has all the files :s? I am sorry, could you please clarify. The way it stands I struggle to understand problem at hand – e.doroskevic Aug 10 '16 at 21:17
  • @e.doroskevic : Sorry for not being clear. But, first thing is that I got my half of answer about how to recover my deleted files. And it worked for me. I updated my question with that link. Actually, I lost all my files before **first commit** was done during stage **initial commit**. – ramkrishna Aug 10 '16 at 23:36

1 Answers1

0

I found it how to recover all the files.

  1. run command: git fsck --lost-found

if you find dandling tree then you can recover them using commands

git cat-file -p <Dangling_tree_name>

and

git read-tree <Dangling_tree_name>

Ref: git deleted everything, how to recover files and folders

ramkrishna
  • 632
  • 1
  • 7
  • 24