I did something terribly dumb and lost a huge amount of uncommitted code. I sincerely ask for your support.
How I lost (summary)
- Had a huge uncommitted/untracked file
lost.py
in local repository. git add lost.py
git push origin branch
( I forgotgit commit
here)git stash pop
(Thinking I committed my changes, I popped few stashes)- Above step resulted in merge conflict
- To undo
git stash pop
, I performedgit reset --merge
- Now I lost
lost.py
from working directory.
Can you please help how to recover the file?
What I tried so far?
git fsck --lost-found --unreachable
. This one showed few dangling blob SHAs but none of them show my lost file.
Here are the full sequence of commands from my console that resulted in lost file.
me@host:~/Projects/my-project ⇒ git status
On branch intsite
Untracked files:
(use "git add <file>..." to include in what will be committed)
upload_int_site.py ----> This is the lost file.
nothing added to commit but untracked files present (use "git add" to track)
me@host:~/Projects/my-project ⇒ git add upload_int_site.py
me@host:~/Projects/my-project ⇒ git push origin intsite
Total 0 (delta 0), reused 0 (delta 0)
To github.com:My-User/my-project.git
* [new branch] intsite -> intsite
me@host:~/Projects/my-project ⇒ git stash pop
Auto-merging config.ini
CONFLICT (content): Merge conflict in config.ini
me@host:~/Projects/my-project ⇒ git status
On branch intsite
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: upload_int_site.py
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: config.ini
me@host:~/Projects/my-project ⇒ git commit -m "upload int site"
U config.ini
error: Committing is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
me@host:~/Projects/my-project ⇒ git reset --merge
me@host:~/Projects/my-project ⇒ git status
On branch intsite
nothing to commit, working tree clean
----- Working tree is clean and lost the file here.