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.
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 .
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.
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.
git reset is a powerful command that can modify the history of your Git repository and fix mistakes you made.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With