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

GitGithubGit Pull

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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).

Solution 2 - Git

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

Solution 3 - Git

Go to the location of file style.css (may be app/css/) using the console. Otherwise there will be pathspec error.

Then execute:

git checkout origin/master style.css

Solution 4 - Git

I intentionally deleted some files from a clone --depth 1.

This brought the main files, and submodule ones, back:

git checkout . -f && git submodule update --checkout -f 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionferonovakView Question on Stackoverflow
Solution 1 - GitCJlanoView Answer on Stackoverflow
Solution 2 - GitneoneyeView Answer on Stackoverflow
Solution 3 - GitprimeView Answer on Stackoverflow
Solution 4 - GitnoabodyView Answer on Stackoverflow