Is it still possible to restore deleted untracked files in git?

╄→гoц情女王★ 提交于 2019-11-26 17:44:18

问题


let's say yesterday I did some changes on my master branch, and I forgot to add, commit them. and in the morning i did

git reset --hard

is it possible to restore deleted files in this situation ?


回答1:


Some better IDEs keep track of your files as a local history. If you removed files externally (say, git reset) you should be able to click in your IDE on parent directory and choose "Compare with local history".

I used this feature successfully in PHPStorm IDE when my untracked files got wiped out by some utility...




回答2:


No................... It isn't.




回答3:


git reset --hard is a very dangerous command, so be careful when you use it next time :)

If you do not have any commit for those files, it seems you have no chance restore them.

Otherwise, reflog command can help you.




回答4:


(Note: The steps seem to have changed a bit, since the accepted answer was posted. But the idea remains the same.)

To add to the accepted answer, I was able to recover my deleted files using Webstorm 2016.

  1. First, I lost my file doing a forced clean using git git clean -f.
  2. To recover it, I went in Webstorm and did the following steps:

    • Go to Project tab for your project, right click to get to 'Show History' under 'Local History'. (As shown in this picture.)

    • Once 'Show History' is clicked, one can see the pop up with 'External Change -> Revert' in it. Click to revert the desired files on right. (As shown in the attached picture.)

    • After the above 2 steps, you should see your file come back in 'Project' tab. 'Local History' pop up will show something like in this attached picture. Reverted to External ChangeYou will get an option to get it add to Git.

    • To untrack it, just do a git reset HEAD <filename> from the command line.




回答5:


git reset --hard won't remove untracked files. git clean will, however.

However if you git add the files, don't git commit them and then run git reset --hard those files will be lost.

But it's ok, as they can be recovered, as shown in this answer. (Well, until the next git gc).




回答6:


You can't access to previous version of untracked deleted files from git, because, of coruse, they do not exist. I would recover them from some backup (maybe there are hidden backup files left by the ide/editor?), or, in alternative, I would avoid working on that filesystem too much and start searching for recovery tools.




回答7:


git fsck may be able to help you.

If you have not done garbage collection yet it might be able to help you. Once you have the blob id you can say:

git show {blobId}




回答8:


In Intellij how to recover the untracked revert changes

Step 1: Select the Folder , Right click on it

Setp 2: Go to Local History, and then go to Show history

Step 3: Select the untracked files that your revert accidentally. then select those file in right side panel and revert the changes, you will get the files in reverted format.



来源:https://stackoverflow.com/questions/9750049/is-it-still-possible-to-restore-deleted-untracked-files-in-git

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