How do I pull missing file back into my branch

蓝咒 提交于 2019-12-03 06:25:37

问题


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

I want to get original style.css back from origin to my dev branch. Unfortunately my git thinks it is up-to-date and wont do anything.

root@debian:~/project.me# git status
# On branch dev
nothing to commit (working directory clean)

root@debian:~/project.me# git pull origin dev
Password for 'https://someone@github.com':
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?


回答1:


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

Hope this helps




回答2:


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




回答3:


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

then execute :

git checkout origin/master style.css




回答4:


I intentionally deleted some files from a clone --depth 1 and this brought the main files, and submodule ones, back.

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


来源:https://stackoverflow.com/questions/9705626/how-do-i-pull-missing-file-back-into-my-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!