Restore Deleted Files In Git

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

转载于:https://www.cnblogs.com/joe-yang/archive/2012/03/30/2425628.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值