10 GIT lines erased 8Gb form my pc - How to get them back? [closed]

℡╲_俬逩灬. 提交于 2019-11-28 18:30:06

Oh boy. I see what you did, and it's not pretty. Let's read the documentation for "git clean":

git-clean - Remove untracked files from the working tree

This means that git-clean deletes files that it cannot restore. Git has some safety measures in place so that you don't accidentally run git clean -- it won't delete directories unless you specify -d, won't delete ignored files unless you pass -x, and won't do anything at all unless you specify -f.

It looks like you turned your home directory into a Git repository, committed the *.c files, and then deleted everything else.

It's basically like running rm -rf *, or del /s *.* in Windows. Don't do that.

Solution

Restore from backup.

If you don't have a backup, then this is a painful object lesson in why we have backups, and you will have to try to recover the deleted files -- and you must turn off your computer and not boot into Windows until this is complete.

Note on "untracked files"

An "untracked file" is a file that is not part of your Git repository. I can see how if you think that untracked files are part of your Git repo, you will try increasingly dangerous things until they are deleted. The untracked files were never part of your Git repo to begin with, so there was nothing you needed to do to remove them from your Git repo.

Note on -f

The -f / --force option means "this command will delete data, and I know what I'm doing." Before you type -f at any command prompt you should reflect for a moment to think about what data this command will delete and make sure that you actually want to delete it.

For example, git rm takes -f as a parameter. The git rm command will refuse to delete a file with uncommitted changes, because this will destroy the changes. Using -f overrides this behavior, allowing you to destroy data with git rm.

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