Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I recover a repo after a Github for Windows crash?

Github for Windows just bombed when I tried making a commit and now git (command line) is telling me every file is new. I've still got a .get folder which is 53mb in size. I'd made about 60 to 100 commits previous to this.

How can I recover my working copy without losing any history or changes?

Git status says:

On branch master

Initial commit

Changes to be committed:
(use "git rm --cached ..." to unstage)

new file: .gitattributes
new file: .gitignore
... (1620 more files)

Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)

modified: Src/Foo/Bar/Index.cshtml

Untracked files:
(use "git add ..." to include in what will be committed)

The Posh Git command prompt looks like this

C:\Projects\Foo [master +1623 ~0 -0 | +0 ~1 -0]>

The output from git log is as follows

C:\Projects\Foo [master +1623 ~0 -0 | +1 ~1 -0 !]> git log
fatal: bad default revision 'HEAD'

UPDATE

I just ran "Verify Database" from the Git GUI and it came back with the following:

dangling tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 dangling commit 30855e0deee8600f10733e6760db54fee2570a38 dangling commit cd8bc69ad56ca5c4d51d0d5028525698158cf3ec dangling commit c934f9823d907cd69c5e08a0159b9de4dfe3da35 dangling commit f958caca247978db978b70460276b5da7582bb06 notice: HEAD points to an unborn branch (master) notice: No default references

like image 408
Greg B Avatar asked Dec 04 '25 18:12

Greg B


1 Answers

ok, first, I duplicated my working copy so I always had a fallback position. Next I ran git fsck which gave the following output.

> dangling tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 dangling commit
> 30855e0deee8600f10733e6760db54fee2570a38 dangling commit
> cd8bc69ad56ca5c4d51d0d5028525698158cf3ec dangling commit
> c934f9823d907cd69c5e08a0159b9de4dfe3da35 dangling commit
> f958caca247978db978b70460276b5da7582bb06 notice: HEAD points to an
> unborn branch (master) notice: No default references

From here, I used

git checkout <some-hash>

Working through the hashes of the dangling commits above. Turns out, the last dangling commit was my most recent commit, so git checkout c934f9823d907cd69c5e08a0159b9de4dfe3da35 got me back to my working copy before the crash.

From here I did git checkout -b master which recreated my master branch at this commit. git status now shows one change, which was the commit I was trying to make. Committing that gets me right back on track.

like image 73
Greg B Avatar answered Dec 07 '25 06:12

Greg B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!