Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT Rebase operation was interrupted by a PC crash. Now repository is unavailable

I have 2 branches in my repository. There were no uncommitted changes in any of them.

I pulled the branch1, checked out branch2, and started a branch2 rebase on branch1.
In the middle of the work my PC crashed.

After it finally booted up, i open GitExtensions to find that my repository is totally empty, i see the flashing 'rebase under way' or something like that, i click it and it pops me the window where i have to chose to fix conflicts, which did not supposed to happen. If i click 'solve' it opens the window where conflicting files should be shown and of course there is none.

I tried to click abort rebase but it said that folder is not a git repository or any of the parents.

Since then i can do NOTHING. I can't abort, can't see commits. Opening git bash just tells me /some/path/to repo/repo name ((...) | REBASE )

when i write git status it says its not a repository.

Well i wouldn't care that much about failed rebase BUT, i noticed that all of my source files turned to binary files and that means, my unpushed commits are LOST, unless you guys can help me recover it.

I wanted to rebase the branch and push it.... this is frustrating.

EDIT 1:

.git directory is in the repository directory (/some/path/to_repo/repo_name/.git) as it should be. The PC crashed at the point when branch2 commits were being reapplied. It means that branch1 commits were already applied to the branch2, the only thing left, was to finish applying branch2 commits. And it crashed after like 10 or 20 commits were applied.

I have now compared the .git direcotries of a cloned repo and the one which crashed.

Cloned repo had these folders:
hooks
info
logs
objects
refs
And these files:
config
description
HEAD
index
packed-refs

The crashed one has an extra folder named rebase-apply, also extra files:
COMMIT_EDITMSG
FETCH_HEAD
ORIG_HEAD

Everything else seems to match. I didnt go into folders deeper. And didn't try to compare file contents.

like image 717
user1651105 Avatar asked Oct 03 '14 11:10

user1651105


1 Answers

After checking .git directory files, i have noticed that ORIG_HEAD and HEAD files contained only NULLS. It seems i have finally figured out how to fix this.

  1. Deleted index file.
  2. Deleted ORIG_HEAD file.
  3. Deleted HEAD file.
  4. Made a copy of FETCH_HEAD (it was pointing to a Branch1)
  5. Renamed the copy to HEAD
  6. Opened GIT Bash
  7. Navigated to repository directory.
  8. Ran git status to check if it sees that the directory is a repository. (It did)
  9. Ran git reset command.
  10. Ran git rebase --abort command.

At this point, all the binary source files were text files. Also index file got recreated.

When i opened repository through GitExtensions, everything seemed to be back to normal, before the rebase. I tried the rebase once more, but it stopped at one of the commits with an error of
error: unable to unpack d447b241eba771f175cb2150eec77ec605a86486 header error: inflateEnd: stream consistency error (no message) fatal: d447b241eba771f175cb2150eec77ec605a86486 is not a valid object

  1. I cloned the repository (from the local GIT server) to another folder.
  2. Copied the source files from recovered repository to the newly cloned one.
  3. Checked that it showed me all the changes i have made are correct and no commits are lost.
  4. Committed all changes as 1 commit (oh well).
  5. Pushed.

Thats it. Now it is working once again. Seems that i have not done any damage to it.

like image 55
user1651105 Avatar answered Sep 23 '22 18:09

user1651105