Remote directory in Git by mistake

By mistake, I deleted the directory in my git repository and committed it.

I did

git checkout LONG_SHA_ID 

where LONG_SHA_ID is the identifier of the previous commit, and I have the directory back, but I also reverted to previous versions of some files that I fixed in the last commit.

How can I recover a deleted directory with the latest version of other files?

+6
source share
3 answers

Do it:

 git checkout LONG_SHA_ID -- /path/of/directory/you/deleted 
+7
source

Make a branch with fixed files and do git reset --mixed HEAD^ . This will undo the commit, so you can try again without deleting the folder.

+1
source

Just return the last commit with

 git revert HEAD 

This will result in the rejection of the last commit. Then just pull it up. You can replace HEAD with the desired revision.

For more on undoing git commit, see here

-1
source

All Articles