Question

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

Was it helpful?

Solution

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.

OTHER TIPS

First of all: Don't panic. Make a backup of your project, including your working folder. Hmm... Actually, make two of them :)

I've still got a .git folder which is 53mb in size.

Git is a pretty resilient tool. An analysis of the object database could "rebuild" your history.

Moreovoer, GHfW logs most of the interactions with the repo. Long story short, there are good chances the GHfW team may help you rescue your repo.

As stated by the announcement blog post

We make sure to read every mention on Twitter. If you find a bug, submit it to support@github.com. Every email is read by a real person.

Send them a mail. Like now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top