1

I started using git four weeks ago to synchronize files between two computers. The last two weeks I did not commit any changes. Yesterday I wanted to add a third computer. In a hurry, I ran some commands on Computer 1 to create a new branch (PreAlgo) and commit the changes of the last two weeks. In parallel on Computer 3, I tried to fetch the current state of the repo.

Unfortunately, all files I added on Computer 1 disappeared. I could recover all my git commands and a little of the responses from Matlab history from both computers. But as I worked in parallel on both, I can not recover the order of the commands between both computers.

I know the code below is an example of how to not use git. The initial branch of Computer 1 was AddFinEval. I am aware that I did a lot of mistakes. Hints for recovering the files are much appreciated.

Commands Computer 1

>> ! git branch PreAlgo
>> ! git commit -m "PreAlgo" --all
>> ! git push origin PreAlgo
>> ! git add PredictAvailability.m    % this file did not diasappear
>> ! git commit -m "PreAlgo" --all
>> ! git push origin PreAlgo
>> ! git add AlgorithmPlayground\     % files from this path disappeared
>> ! git add Predictions              % files from this path disappeared
>> ! git commit -m "PreAlgo" Initialisation.m
>> ! git push origin PreAlgo
>> ! git commit -m "PreAlgo" Initialisation.m
>> ! git push
>> ! git checkout PreAlgo
>> ! git commit -m "PreAlgo" --all
>> ! git checkout AddFinEval
Switched to branch 'AddFinEval'
>> ! git commit -m "PreAlgo" --all
Untracked files:
   (list of some untracked files that did not disappear)
nothing added to commit but untracked files present (use "git add" to track)
>> ! git push origin AddFinEval
To https://github.com/myname/myrepo

Commands Computer 3

>> ! git fetch --all
>> ! git reset --hard origin/master
>> ! git pull
>> ! git fetch --all
>> ! git reset --hard origin/master
>> ! git pull
>> ! git checkout PreAlgo
>> ! git fetch --all
>> ! git reset --hard origin/master
>> ! git checkout AddFinEval
>> ! git fetch --all
>> ! git reset --hard origin/master
>> ! git fetch --all
>> ! git reset --hard origin/AddFinEval

As proposed here How to restore files that were removed by git?, I tried

! git fsck --lost-found
! ls .git/lost-found/other

but the two files I found in lost-found contain only their title. However, in .git/objects/pack I found a 600MB .pack file created at about the time the files disappeared. One of the disappeared folders contained some large .mat files.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • I don't see anything that looks disastrous in the commands on computer 1 - is it the case that the files you added to PreAlgo just aren't included in AddFinEval? I think you should just be able to checkout PreAlgo? (But I think some git branching revision might be useful to you) – 9bO3av5fw5 Oct 03 '20 at 14:46
  • Thanks so much for your reply @9bO3av5fw5, you were right! I recognized that files are missing after Matlab started to create a lot a files newly that were stored in `Predictions`. When I tried to checkout to PreAlgo I received `error: The following untracked working tree files would be overwritten by checkout:` and a list with the new created files that was too long to be displayed completly. Thus is ended with `Aborting`. First I did not dare to try stashing or delete the new files. But now I did, checked out to `PreAlgo` and all missing files I are there. – konjunkturkrise Oct 03 '20 at 16:11

0 Answers0