Restore files deleted with git clean -df

后端 未结 3 568
北海茫月
北海茫月 2021-01-25 10:39

I was trying to clear my git after adding files from the wrong directory and ran the git clean -df function. This resulted in all my user data being deleted.

I haven\'t

相关标签:
3条回答
  • 2021-01-25 10:59

    If you're using Eclipse, and you're only missing code or text, don't despair, not all may be lost. Go to:

    [WORKSPACE]/.metadata/.plugins/org.eclipse.core.resources/.history
    

    Then use grep (*nix), FINDSTR (Windows) or a similiar tool to search for text snippets you know to have occurred in the deleted files. Eclipse keeps a lot of local history revisions around, so if you worked on these files recently, you will probably have a lot of matches. Then you need to find most recent one of these, which can be a bit tricky.

    To give an example: After doing a quick git clean -d -fx to show this dangerous feature to a colleague, I was missing an untracked java code file, of which I knew it contained the String XrefCollector. I was able to find the last local history revision by doing this:

    find . -printf "%T@ %p\n" | sort -n | cut -d" " -f2 | xargs grep -l XrefCollector | tail -n1
    

    Here, find prepends the date (epoch) to the files, sort sorts (numerically), cut removes the date again, and xargs passes the filenames on to grep, which searches for the desired string. Finally, tail only shows the last line of output.

    0 讨论(0)
  • 2021-01-25 11:03

    There's no way to recover from this unless you had a backup or want to explore using undelete utilities. Git is not saving backups anywhere.

    0 讨论(0)
  • 2021-01-25 11:24

    Short answer and most probable there is not!!

    Still some IDE's track and store locally this information see for example: Is it still possible to restore deleted untracked files in git?

    So depending on your IDE or text editor it still might be possible.

    0 讨论(0)
提交回复
热议问题