1

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 forgot git 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 performed git 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.
snackbar
  • 93
  • 7
  • Try `git cat-file --batch-check --batch-all-objects | grep blob` to list all blobs. – ElpieKay Aug 05 '21 at 01:43
  • 1
    It is weird, a simple `git fsck` should have found that. – Marco Luzzara Aug 05 '21 at 07:14
  • 1
    @MarcoLuzzara: I've been meaning to get around to testing for new `git fsck` bugs in particular Git versions: see https://stackoverflow.com/a/68313170/1256452 and comments... it's possible someone introduced a bug here as these things do happen. – torek Aug 05 '21 at 10:28
  • Try VonC's steps (`git fsck` with extra explicit options) from related question: https://stackoverflow.com/q/68310226/1256452 – torek Aug 05 '21 at 10:29

0 Answers0