I think I just totally messed up.
I've been working on a project for 2 days and I was trying Magit in emacs to commit the project but I kept getting back to the staging area without finishing the commit.
Long story short, I exited emacs and was back in the command line and everything was fine with the files, but git status
said that I should do a git revert --abort
or some other option I don't recall now.
Well, git revert --abort
seemed ok, since I wanted to abort whatever git was doing and being left with my files, but it actually took all my files to the last commit.
I've lost hours upon hours of work. Is there any way to go back to the state before this command was issued?
My git reflog is:
5fba267 HEAD@{0}: commit: Clones the spacemacs repo needed for emacs
2c9ced3 HEAD@{1}: commit: Major changes to emacs configuration
d38f9db HEAD@{2}: commit: add initial emacs configuration and vimwiki
e0e28d0 HEAD@{3}: commit: Vim whitespace showing modifications
The work I did was all after that 5fba267 HEAD@{0}
EDIT with answer: Using the invaluable help from codeWizard I managed to do it in the end.
Using the dangling blob
didn't work so much because there were almost no files there. This might be because while trying to solve it I changed one of the files back to the last checkout and git deleted the other files from the dangling stuff.
But, all the information needed is actually in the dangling commit
part.
So here is what I did with the help of codeWizard
First, copy your repository directory in full and only work from there.
Next issue the git command:
git fsck --full
It outputs something like:
Checking object directories: 100% (256/256), done.
dangling blob 0c8676d28b6b063592493bce281530fb7098a41c
dangling blob 5040b2db1a895ea4aa69c993e0df7cd48823eaec
dangling blob 5ffc6f27406506a01aa13e9b773b574840cef7ac
dangling blob 676efa400477c8d92787a39978f73114f39e0f89
dangling commit 8a44f14eb0821859c0e1cdf0d81038c8431a1007
dangling commit 968e27b0d49b899ab2d43a964b561e4dfd2aa41f
dangling commit 9f5e56caa8b904d93acd43b05f3817ff975a0423
Now, showing the dangling commit
using the SHA:
git show - p 8a44f14eb0821859c0e1cdf0d81038c8431a1007
The output will actually be the git diff for that staged but never committed changes:
commit 8a44f14eb0821859c0e1cdf0d81038c8431a1007
Author: Me <me@gmail.com>
Date: Sun Jan 3 02:07:10 2016 +0000
oO
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ec6eec8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/#bootstrap.sh#
+/emacs.d/#init.el#
+*~
diff --git a/bootstrap.sh b/bootstrap.sh
What you need to do it to check the Date
and see the one that suits you (actually they where all from the same period for me).
After that you just have to issue the command:
git checkout 8a44f14eb0821859c0e1cdf0d81038c8431a1007
And you will be will all your files added to commit but that you've never committed.
Only issue I've found was that after that you will be left with the git status
:
HEAD detached at 8a44f14
nothing to commit, working directory clean
So I just copied all the changed files back to my original repo and everything was fine.