You may be able to recover files from an interrupted commit
Based on the observation of @ the-malkolm.
From the information in the question there are no commits, and the files were not tracked at any time. Since git is not aware of any files that have been deleted.
However, there is hope. Just because you tried to migrate your files before deleting them, there is a phantom commit floating around with all your files.
Here is an example:
$ git init Initialised empty Git repository in /tmp/so/.git/ $ echo "find this text" > README.md $ git add README.md $ git commit -v Aborting commit due to empty commit message. $ git rm -rf . rm 'README.md' $ git status
The above simulates the events in the question, and usually it's time to rewrite the code again. No commit, file missing.
Determine that interrupted commit
However, checking the .git repository gives some information:
$ tree .git/objects/ .git/objects/ ├── 91 │ └── 9cdf847a6af7c655c8de1d101385f47f33e0f9 ├── d6 │ └── 7d51abe2521dcd00cec138b72f5605125c1e41 ├── info └── pack
There are objects in the git repository, despite the lack of commits. You must determine which of the two objects is tree :
$ git ls-tree 919cdf fatal: not a tree object $ git ls-tree d67d51 100644 blob 919cdf847a6af7c655c8de1d101385f47f33e0f9 README.md $
The first link is a blob representing the README.md file - in the repository there will be one frame per file, the second in this example, a link to a tree.
Playback copy
Once the tree hash is identified, it can be used to restore the index using read-tree :
$ git read-tree d67d51abe2521dcd00cec138b72f5605125c1e41 $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: README.md # # Changes not staged for commit: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: README.md $
At this time, the working copy is empty, but the lost files are set for commit.
Lock them:
$ git commit -m "phew"
And check to match the committed state of the repository:
$ git checkout . $ ls README.md
And then all the files exist and were committed.