Git pull deleted uncommitted changes
For me the following worked:
- Go to the affected file.
- Right click and choose Local History and select Show History. From there you can see the history of changes made to the file, and then choose the time you want to bring back the file to.
- You will get two windows with the left one having >>. Click on all the >> and this will send your changes to the right window.
- Close the window and here you go with your file restored to where you wanted it to be.
I hope it helped!
You can get them back. Even though the only thing pointing to it was the index, git add
still put the added content in the repo. I'd start with a git fsck
to find "dangling" (git's slightly quirky spelling of "unreferenced") blobs and git cat-file -p
those blobs, if there's too many I'd do something like find .git/objects -type f | xargs ls -lt
.
I agree with the accepted answer, however in my case there were too many results for git fsck
. This solution is what helped me locate the lost files:
Search for a string in the missing file(s):
grep -rin <string_in_missing_file> .git/
For example:
grep -rin MyClassName .git/
Search results:
.git//lost-found/other/3cfaa36226f52a5c1b38c2d2da3912656c998826:5:class MyClassName extends ParentClass
.git//lost-found/other/e7b8923de4afb230ad523b5b515f50cb9c624248:5:class MyClassName extends ParentClass
Where search results are:
.git/<path_to_file>:<line_number_of_found_string>:<found_string_and_context>
Then to restore the file:
git cat-file -p 3cfaa36226f52a5c1b38c2d2da3912656c998826 > ../<desired_file_path>/MyClassName.php