0

I have a GitHub private repo, to which I push my changes via Visual Studio for Mac 2019.

Backstory

I added a readme file on GitHub directly, then a few weeks later I edited my local copy and tried to push my changes. I could not do it, cause it said that I had changes remotely that i don't have locally, which is fine.

Then I stashed my changes in VS for Mac, and tried to pull, which seemed to work.

Then I tried to apply my stash, and I kept getting random errors. Thought I might have to update VS for Mac, which I also did.

Then after updating, I could not open any files in my local repo, because it kept saying BeginBatchUpdate called twice without calling EndBatchUpdate.

I restarted VS for Mac, then I tried to build my project, but I noticed that a file was missing.

I tried to checkout earlier commits, but it's as though it never existed - the file is not in there in earlier commits either... I tried to git reset --hard, no luck, I tried to check if I did anything weird in git reflog, there is nothing in it other than commits, resets, and checkouts, so I have no idea how the file could just disappear like this.

Question

Is there any chance to get back that randomly removed file?

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
iSpain17
  • 2,502
  • 3
  • 17
  • 26

1 Answers1

0

In git your main node of versioning is the commit. First I would try to list all commits which had anything to do with your readme file. If that list is nonempty, then checking out those commits should enable you to bring that file back.

If the list of commits is empty, then you have no commit for that file, which means that it was never actually versioned.

The fact that you stashed the readme file makes me think that it was probably not committed, because if it was committed, then you would have had a merge when you have executed git pull and the worst-case scenario would have been to solve some merge conflicts.

So, I suppose you cannot recover your file with git and for the future I suggest that you should always do a commit & merge to handle version differences rather than stashing your changes.

There might be possibilities to recover that file, like this one: https://www.wondershare.net/ad/data-recovery-mac.html?gclid=Cj0KCQiAqY3zBRDQARIsAJeCVxNPQ4CPnwkNJ5DvKIlrmDgT6gtFjldFcrNK-k7njZJLxJxC6AeABFMaAjwmEALw_wcB

However, the loss of a readme file, unless it was very long might be a solvable issue by rewriting it. Important is to learn from this issue and ensure that you will not lose your work in the future with much more dire consequences.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • The readme file is committed. *"I had changes remotely that i don't have locally"*I will check the commits of the readme file thank you – iSpain17 Mar 07 '20 at 12:40
  • Also, I never stashed the readme file, as it had been only remotely available. I stashed my local changes. And the file that disappared was not part of the stashed changes. It was one of the first files in this repo, created almost a year ago. That is why I have no idea why the file just completely disappeared... – iSpain17 Mar 07 '20 at 12:48
  • I checked those commits, they don't have the file either. As if the file never existed... – iSpain17 Mar 07 '20 at 12:52
  • @iSpain17 I see, so the readme was only available remotely? I thought it was on your local end. I think the file disappeared because you have done a git reset. That negates every change, so if you had a merge conflict and then executed git reset --hard, then files and changes disappear. Run git pull again. – Lajos Arpad Mar 07 '20 at 13:20
  • I pulled a lot of times, nothing happens. I started to accept it, because it was a View file from an MVVM project. I have the viewmodel, so its not going to be that hard to rebuild it. – iSpain17 Mar 07 '20 at 13:45