Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover from Git reset --hard in Eclipse

I accidentally did something to my git repo and I don't know if I can save my project at this point...

I had a bunch of changes that I made. Then I wanted to delete my last commit so that I could make this new commit instead. I forgot to do git stash. So when I ran git reset --hard [second-to-last commit] it erased everything I had done. It was stupid, but is there anything I can do to rescue my recent work?

I'm using Eclipse IDE.

like image 435
brienna Avatar asked Jul 27 '18 17:07

brienna


People also ask

How do you get back changes after git reset hard?

Hard reset explained. In this case, you can restore the file using either git checkout or git reflog . You can find the hash-ID of the previous commit from the command: git log . In case you don't have the hash ID, you can use the command git reflog .

Can I undo a git reset?

You can safely undo your local changes using the reset command. However, if you want to undo changes you have committed to a remote repository, always use the revert command instead.

What after git reset hard?

Using the git reset --hard option resets the current branch tip, and also deletes any changes in the working directory and staging area. Therefore, it resets index entries to the state of the specified commit.

What does git reset do in eclipse?

git reset is a powerful command that can modify the history of your Git repository and fix mistakes you made.


1 Answers

Short answer for git, NO.

It is impossible to recover file that you did not add or stash


In general the best way to handle these kind of problem is to rely on the IDE instead.

In Eclipse, you could look under this path

.metadata/.plugins/org.eclipse.core.resources/.history/

So, you could use those commands to find the most recent changes,

cd .metadata/.plugins/org.eclipse.core.resources/.history/
ls -al * | grep "<today's date>" | grep "r\-\-" | sort -k 6

Note that you will have to replace "<today's date>" with "Jul 27" for example.

Then you could use

find . -name <filename>

Note that you will have to replace "<filename>" with something like "7098a672a2bc00111703c0e5cbee369d" found with the previous command.

For more info look at this.

like image 75
scharette Avatar answered Sep 20 '22 21:09

scharette