Git - deleted some files locally, how do I get the

2020-02-16 06:04发布

I've deleted some files on my PC, how do I download them again?

Pull says: "Already up-to-date"

Thanks

标签: git
6条回答
Root(大扎)
2楼-- · 2020-02-16 06:29

Since git is a distributed VCS, your local repository contains all of the information. No downloading is necessary; you just need to extract the content you want from the repo at your fingertips.

If you haven't committed the deletion, just check out the files from your current commit:

git checkout HEAD <path>

If you have committed the deletion, you need to check out the files from a commit that has them. Presumably it would be the previous commit:

git checkout HEAD^ <path>

but if it's n commits ago, use HEAD~n, or simply fire up gitk, find the SHA1 of the appropriate commit, and paste it in.

查看更多
beautiful°
3楼-- · 2020-02-16 06:29

Also, I add to do the following steps so that the git repo would be correctly linked with the IDE:

 $ git reset <commit #>

 $ git checkout <file/path>

I hope this was helpful!!

查看更多
等我变得足够好
4楼-- · 2020-02-16 06:32

You need to check out a previous version from before you deleted the files. Try git checkout HEAD^ to checkout the last revision.

查看更多
乱世女痞
5楼-- · 2020-02-16 06:41

If you have deleted multiple files locally but not committed, you can force checkout

$ git checkout -f HEAD
查看更多
Summer. ? 凉城
6楼-- · 2020-02-16 06:41

If you deleted multiple files locally and did not commit the changes, go to your local repository path, open the git shell and type.

$ git checkout HEAD .

All the deleted files before the last commit will be recovered.

Adding "." will recover all the deleted the files in the current repository, to their respective paths.

For more details checkout the documentation.

查看更多
够拽才男人
7楼-- · 2020-02-16 06:43

git checkout filename

git reset --hard might do the trick as well

查看更多
登录 后发表回答