Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pull a missing file back into my branch?

I have cloned a Git project into a local Git repository. Then I have done something nasty to one of the files and in that panic I deleted file physically from the drive (rm style.css) and also removed it from Git (git rm style.css).

I want to get the original style.css file back from origin to my development branch. Unfortunately my Git thinks it is up-to-date and won't do anything.

cd ~/project.me
git status

# On branch dev
nothing to commit (working directory clean)

git pull origin dev

Password for 'https://[email protected]':
From https://github.com/somewhere/project.me
* branch            dev        -> FETCH_HEAD
Already up-to-date.

What do I need to do to tell git that I want to download original style.css file back into my dev branch?

like image 360
feronovak Avatar asked Mar 14 '12 16:03

feronovak


People also ask

How do I extract a lost file in git?

If you have lots of files to restore (as I did) you can use: git diff --name-status | sed -n '/^D/ s/^D\s*//gp' | xargs git checkout origin/master which will re-checkout all the deleted files.

How do I retrieve a branch?

To restore the branch, select the ... icon next to the branch name and then select Restore branch from the menu. The branch will be recreated at the last commit to which it pointed. Note that branch policies and permissions will not be restored.


2 Answers

Use git checkout. In your case:

git checkout origin/master style.css

This command will update the requested file from the given branch (here the remote branch origin/master).

like image 171
CJlano Avatar answered Oct 12 '22 12:10

CJlano


If you want to restore all the missing files from the local repository

git checkout .

Warning: This method also restores all changed files and drops all the changes

like image 77
neoneye Avatar answered Oct 12 '22 13:10

neoneye