6

git clean -f -d removed files from my local directory as well How do I retreive them? I used it to remove untracked directories and files and found that it also deleted it from my local file system. Is this possible? What did i do wrong and is there a way to retreive them?

4

3 回答 3

4

As a previous answer says, if you're working on Linux, you can't retrieve them. They're gone: that's the point of "git clean". Unless you're using a filesystem capable on doing snapshots but then, you would probably know how to get them back.

If your goal was to avoid seeing them in "git status", you have two possibilities:

A)

git status -uno

does not print untracked files and directories.

B) If there are a fixed set of files (or a filename pattern) that you will never want to see in "git status" nor put them under versioning, you can "ignore" them. You simply have to put their name or pattern in a file named ".gitignore" at your repository's root.

This is typically used for generated files.

The following example ignores filenames ending with ".html" and the file called "out/myFile.txt":

*.html
out/myFile.txt

See

git help ignore

for more info.

于 2013-05-17T21:07:18.800 回答
1

The files deleted by git clean were untracked, which means git didn't keep an extra copy of them. If you need to retrieve them, your best bet is to immediately remount the filesystem read-only, and run whatever deleted file recovery tool is appropriate for your operating system.

于 2013-05-17T20:51:07.713 回答
1

This really depends upon how you deleted them. In Windows these files should have just gone to the recycle bin. In Linux I believe git is using the rm command so you should do a quick search on how to recover files accidentally deleted with rm.

于 2013-05-17T20:53:34.210 回答