I've just started learning how to use git
today, progressing well.
As an experiment, I used push
to upload two directories (containing two files each) and two files in the root directory. This worked fine.
I then deleted one of the two directories that I have locally (but not on git). When I use git status
it seems to be aware of this:
deleted: test/Testfile.as
deleted: test/Testile2.as
But when I use git pull
to get my files back, they don't seem to return to my local folder. I've also tried git fetch
.
The only way I seem to be able to get everything back is git clone
, but that doesn't seem logical as I need to delete my master directory locally and then clone it back again (or alternatively specify a new location for the cloned files).
What is the appropriate way to retrieve files and folders from github that have been deleted locally?
STRONG SUGGESTION: 1) Do a "pull" from your remote repo into a NEW repo (don't do any more damage to your local repo). 2) Try "checkout" ... or even "revert" in your new, local, repo: atlassian.com/git/tutorials/undoing-changes/git-revert. 3) Update the remote repo when you're sure everything is OK.
You can restore a deleted file from a Git repository using the git checkout command. If you do not know when a file was last deleted, you can use git rev-list to find the checksum of the commit in which that file was deleted. Then, you can check out that commit.
Deleting the . git folder does not delete the other files in that folder which is part of the git repository. However, the folder will no longer be under versioning control.
Listing all the deleted files in all of git history can be done by combining git log with --diff-filter . The log gives you lots of options to show different bits of information about the commit that happened at that point.
git pull
just merges the fetched commits in your working directory and will not restore your deleted directory ( but might warn you about conflicts.)
If you have deleted the folders in your working directory, you have to do:
git checkout -- test
to get it back.
Or you can do git reset --hard
to completely bring your working directory to HEAD state.
you want to return your repository to the previous working version. this is a job for git-reset.
git reset --hard
be sure to read through this useful explanation of git-reset
you could also check out those files if you wanted to:
git checkout -- test/
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