可以删除在Git中添加但未提交的文件吗? [英] Can deleted files that are added but not committed in Git be recovered?

查看:275
本文介绍了可以删除在Git中添加但未提交的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的新手,我犯了一个愚蠢的错误,我通过rm *命令删除了一些重要的文件。但是,我确实使用git add来添加这些文件,但不提交。删除还没有添加。那么有什么方法可以恢复这些被删除的文件。



任何建议或答案,将不胜感激。谢谢。因为这些文件已经存在于你的暂存区(index)中,所以只需使用提交它们就可以了。 没有任何参数。这将提交索引的内容,而不管工作树的当前状态。



然后你可以使用 git reset --hard (如果你没有对你想保留的树进行其他更改)或者 git checkout FILE1 FILE2 ... 来将丢失的文件恢复到你的工作树。


I am new to git, and I just made a stupid mistake, that I deleted some important files by "rm *" command. However, I did use "git add" to add those files, but not commit. the deletion is not added yet. So is there any way to recover these deleted files.

Any suggestions or answers would be appreciated. Thanks.

解决方案

Since the files are already in your staging area (index), simply commit them using git commit without any arguments. This will commit the contents of the index regardless of the current state of the working tree.

Then you can use git reset --hard (if you don't have other changes in the tree you want to keep) or git checkout FILE1 FILE2... to restore the lost files into your working tree.

这篇关于可以删除在Git中添加但未提交的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆