6

By mistake I have deleted a directory in my git repo, and commited it.

I have done

git checkout LONG_SHA_ID

where LONG_SHA_ID is the ID of the previous commit, and I have got the directory back, but also I have got back the previous versions of some files that I have fixed in the latest commit.

How can I get back the deleted directory, with the latest version of the other files?

Christian Strempfer
  • 7,291
  • 6
  • 50
  • 75
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167

3 Answers3

7

Do this:

git checkout LONG_SHA_ID -- /path/of/directory/you/deleted
manojlds
  • 290,304
  • 63
  • 469
  • 417
1

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

-1

Just revert back the last commit by

git revert HEAD

That will back out the most recent commit. Then just push it up. You can replace HEAD with the revision you want out.

For more details about undo a git commit, look on here

Community
  • 1
  • 1
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105