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?
The command can also be used to restore the content in the index with --staged , or restore both the working tree and the index with --staged --worktree . By default, if --staged is given, the contents are restored from HEAD , otherwise from the index. Use --source to restore from a different commit.
If you're using the Tower Git client, you'll find the operations described above conveniently available in the GUI. Even better, in cases like committing a file deletion and then wanting to revert it, Tower's awesome undo feature lets you get the file back by simply pressing CMD-Z!
The folder is created when the project is initialized (using git init ) or cloned (using git clone ). It is located at the root of the Git project repository. If we delete the . git folder, the information saved by Git will be lost, and the directory will no longer act as a Git repository.
A deleted repository can be restored within 90 days, unless the repository was part of a fork network that is not currently empty. A fork network consists of a parent repository, the repository's forks, and forks of the repository's forks.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With