I have deleted all the contents inside a folder and the folder is empty. I still had a copy in my remote repo. But when I did a git pull
it didn\'t put back the
The only thing that worked for me was to checkout the repo in another folder. Assume the current repo is in /home/me/current
.
I then did
git clone /home/me/current /home/me/temp
This make a separate clone of the repo in /home/me/temp
I can now go to /home/me/temp
and do whatever I want. For example
git reset --hard commit-hash-before-delete
Now I can copy the deleted file folder back
cp -r /home/me/temp/some/deleted/folder /home/me/current/some/deleted/folder
And delete the temp folder
rm -rf /home/me/temp
The examples of
git checkout -- some/deleted/folder
git checkout -- some/deleted/folder/*
DO NOT WORK
$ git checkout -- some/deleted/folder/*
zsh: no matches found: some/deleted/folder/*
$ git checkout -- some/deleted/folder
error: pathspec 'some/deleted/folder' did not match any file(s) known to git.
Other examples like
git reset --hard HEAD
are destructive beyond just the deleted files. Any other changes will also be lost.
Similarly
git reset --hard some-commit
will lose any commits after some-commit
for uncommited deletions, Its as simple as this :
git reset HEAD rel/path/to/deleted/directory/*