Lost all my staged but unmanaged changes after git revert --bort command
I guess I just totally messed up.
I have been working on a project for 2 days and I tried to Magit in emacs to execute the project, but I kept returning to staging area without finishing committing.
Long story short, I quit emacs and returned to the command line and everything was fine with the files, but git status
said what I should do git revert --abort
or some other option that I don't remember now.
Well, git revert --abort
looked ok as I wanted to abort whatever git was doing and stayed with my files, but in fact it took all my files until the last commit.
I lost my watch during business hours. Is there a way to get back to the state before this command was issued?
My git reflog:
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 after this 5fba267 HEAD @ {0}
EDIT with answer: Using the invaluable help from codeWizard I managed to get it done at the end.
Using it dangling blob
didn't help because there were almost no files there. Perhaps this is because in trying to solve the problem, I replaced one of the files with the last checkout and git removed the other files from the dangling things.
But all the information you need is actually in the part dangling commit
.
So here is what I did with the codeWizard
First copy the entire repository directory and work only there.
Then run 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 dangling commit
with SHA:
git show - p 8a44f14eb0821859c0e1cdf0d81038c8431a1007
Actually the output will be a git diff for delivered 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 do you need to do to check Date
and see the one that suits you (in fact they are where everything is from the same period for me).
After that, you just need to run the command:
git checkout 8a44f14eb0821859c0e1cdf0d81038c8431a1007
And you will use all your commit files, but which you never committed.
The only problem I found is that after doing this you are left with git status
:
HEAD detached at 8a44f14
nothing to commit, working directory clean
So, I just copied all changed files back to the original repo and everything was fine.
source to share
First of all, back up the entire folder to start from there.
Secondary: yes if you made your files?
Have you committed or at least git add
them?
If you have poorly explained how you can find them and return them,
if at least you haven't added them to the index and then lost them.
Update me and update your answer accordingly.
How to recover deleted files (provided they are committed)
The trick is to check the previous commit of the last good commit (this should be your re-completion in your question)
Then check the version on the commit before using the caret character (^):
git checkout <last good commit>^
The trick is this ^
which denotes a previous commit
I added git as well and they were in a staging area ready to commit, but I never passed the commit part.
Here is an example on how to lose a file
So you're saved (but still you have some work in front of you.)
- Folder backup (as you already did)
- execute
git fsck --full
How to recover a lost file
Run git fsck --full
and then loop over the files to check which one belongs to you usinggit cat-file -p <SHA>
As you can see in the sample, I was able to restore the un-commitd file b.txt
source to share