您的位置:首页 > 其它

Restore Deleted Files In Git

2012-03-30 16:55 302 查看
Ever been working on a project for a while, then go work on something else, then come back after a few weeks? Sure you have.

Ever come back and somebody deleted your nice nginx config file you had in there for your local dev server? Ever wonder where the hell it went? Well wonder no more!

I had this happen a couple days ago. Somebody deleted my
nginx.conf
file. It was just gone.

Find it!

First things first, I had to find the file. A little bit of Googling1 and looking at git docs, I found this:

git log --diff-filter=D --summary

This prints the summary of all commits that have deletes. Awesome. Now you can look through in which commit your file was deleted.

Restore it!

Once you have that, you can use the commit hash in the next command:

git checkout <COMMIT>^ -- <file>

And that will restore your file. Rinse and repeat for multiple files.

Note: the file name is Case sensitive

demo:



http://verboselogging.com/2010/10/19/restore-deleted-files-in-git
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: