4

I had changes in a few files and some new files

git pull: said I had conflicts in a few files

I did :

git stash
git pull
git stash pop

I expected conflicts but there were none.

Instead many files are now just empty. current uncommitted changes show everything deleted from these files.

Solution I see is: clone the repository. "somehow recover" my last popped stash and save it as a patch and apply there.

How do I recover this (it is not in the stash list anymore)

I don't see the last stash using :

gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

and

git fsck --no-reflog | awk '/dangling commit/ {print $3}'

gives :

error: object file .git/objects/02/7745a5151a6237eb1dcd8e4f0df10328809669 is empty
error: object file .git/objects/02/7745a5151a6237eb1dcd8e4f0df10328809669 is empty
fatal: loose object 027745a5151a6237eb1dcd8e4f0df10328809669 (stored in .git/objects/02/7745a5151a6237eb1dcd8e4f0df10328809669) is corrupt

What do I do? What happened?

Justin Howard
  • 5,504
  • 1
  • 21
  • 48
Sachin Sharma
  • 1,446
  • 4
  • 18
  • 37
  • I don't think this has to do with `git stash`, the fsck indicates your repository is damaged. `git stash pop` didn't do that. Did your computer crash? – Schwern Feb 03 '16 at 22:14
  • no my computer didn't crash. although might be disk corruption issue. what do i do now? – Sachin Sharma Feb 04 '16 at 04:37
  • Now you look into fixing a corrupted repository. Here's one question on the subject. http://stackoverflow.com/questions/8271263/repair-corrupted-git-repository – Schwern Feb 04 '16 at 21:21

2 Answers2

3

I find the official document has a solution.

Recovering stash entries that were cleared/dropped erroneously

If you mistakenly drop or clear stash entries, they cannot be recovered through the normal safety mechanisms. However, you can try the following incantation to get a list of stash entries that are still in your repository, but not reachable any more:

git fsck --unreachable |
grep commit | cut -d\  -f3 |
xargs git log --merges --no-walk --grep=WIP
feng zhang
  • 1,193
  • 7
  • 8
-4

Have you tried using:

git stash list

You should have a list of stashes that you've done. Then you can select the one you want to apply:

git stash apply stash@{1}

Before you apply the stash I imagine you want to have the HEAD on same position before you ran the first git pull.

Tim Hysniu
  • 1,446
  • 13
  • 24