With the great help of my former colleague, I figured out how to recover from this. You will probably want to do this as a last resort, because you are likely to lose some information, and it may not work because of corruption.
Name the damaged workspace “corruptWorkspace” and the workspace that needs to be fixed to fixWorkspace. The first step you need to do is create a new workspace to recover and copy the object and refs:
- $ mkdir fixWorkspace
- $ cd fixWorkspace
- $ git init
- $ cp ../corruptWorkspace / .git / objects.git -r -a
- $ cp ../corruptWorkspace / .git / refs.git -r -a
From here you can restore the branch / commit.
- Find the branch you want to restore by finding it in .git \ refs \ heads or in the .git \ logs \ HEAD file
- Open a text editor and you will find the last SHA commit for this branch in the branch file or the second SHA column of your last record for the branch in the HEAD file
This command should be readable and show the latest commit changes
- $ git show [commit SHA]
After confirming that the branch looks ok, try checking
- $ git checkout [branch name]
Then you can reset the branch
- $ git reset --hard
At this point, you have the latest perfect version of your branch. The next step is to restore the stash file.
- Find the backup you want to restore by finding it in .git \ refs \ stash or in .git \ logs \ stash file
- Open in a text editor and you will find the last SHA commit for this cache in the stash file or the second SHA column of your last stash entry for the branch in the stash file
List the files that are in the backup storage for recovery, from here you can get the location and file that were hidden for use to restore the file
- $ git show --name-only [stash SHA]
Recover Saved Files
- $ git show [stash SHA]: [full path to file]> [full path to file]
After you have completed the above command for all your files with files, you have finished receiving your branch and your file with files. if the configuration file is not corrupted, you can even copy the definition of origin and click on your changes.
Luck
source share