Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't git pull bring back directories that I've deleted?

Tags:

git

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?

like image 747
Marty Avatar asked Feb 16 '12 03:02

Marty


People also ask

How do I restore a directory in git?

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.

How do I undo a git deletion?

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.

What happens if the .git directory gets deleted?

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.

Does git show deleted files?

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.


2 Answers

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.

like image 170
manojlds Avatar answered Oct 23 '22 18:10

manojlds


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/ 
like image 42
checkorbored Avatar answered Oct 23 '22 18:10

checkorbored