0

Which Git then proceeded to sync (overwrite) files from my repository (not github), to my local files. I have lost an entire day or more of work.

Is there a way to revert what happened? What did happen? I am side myself.

Rich

Richard Testani
  • 1,474
  • 4
  • 15
  • 29

1 Answers1

1

If the application stashed the changes instead of removing them you will be able to restore it. Try this:

git stash list

Hopefully you'll get an output stash@{0}: ..., which should be easily restored with:

git stash apply

However if there is more than one stash you'll need to call:

git stash apply stash@{number}

If it's more complicated, look into docs for stashing.

Note that if there's no stash, the uncommited changes are gone. Forever. If you don't have an editor that preserves changes or has some backups then I don't think there's anything you can do.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
  • So I ran stash, heres the output:stash @{0}: GitHub: Stashing to pull in remote changes stash@{1}: GitHub: stashing before switching to master stash@{2}: GitHub: stashing before switching to develop – Richard Testani Oct 15 '16 at 01:34
  • Seems stash 0 was what I did, is i possible to reverse was I did? – Richard Testani Oct 15 '16 at 01:35
  • 1
    @RichardTestani as it's in the answer: `git stash apply stash@{0}`, but `git stash apply` should fetch the recent stash anyway. – Peter Badida Oct 15 '16 at 09:01
  • When I run the command this error is output: error: Your local changes to the following files would be overwritten by merge: sites/coobie/config.codekit Please, commit your changes or stash them before you can merge. Aborting -- There was one file that was not overwritten when all this happened. – Richard Testani Oct 15 '16 at 12:18
  • 1
    @RichardTestani I'm not sure what's happening here. Was the sync successful without any errors? If so, the master branch in local repo should be even with the master branch in remote repo and the changes before sync in the stash (test with `git diff origin/master../master`). If there were some commits merged and it won't allow you to get changes from stash because of that, just revert the commits (`git reset HEAD~NumberOfCommits`). More info e.g. [here](http://stackoverflow.com/q/14318234/5994041). – Peter Badida Oct 15 '16 at 12:47
  • After clicking sync, and the process was done - there was a warning or error about overwriting or merging. I was so unsure what had just happened and concerned that all the files I was about to commit were merged I dismissed it pretty quickly. – Richard Testani Oct 15 '16 at 12:58
  • if I were to try to reset the HEAD, how do I know what value to use for number of commits? – Richard Testani Oct 15 '16 at 13:06
  • 1
    Ok then, `git remote` will print the remotes. The other, not "origin" is your upstream most probably if you have only two. Use that in the diff command I pasted above. If there's no diff, the branches are even. If there _is_ diff, the merge didn't happen and it only fetched the changes from upstream (`git fetch upstream`). Re the number of commits - `git reset HEAD~1` means revert to previous commit (revert one commit). You need to `git log` and count how many commits are there until the last commit that was on your local repo. Reset only if you actually need to get rid of those new commits. – Peter Badida Oct 15 '16 at 13:11
  • 1
    Strange, its only showing that one file that was not overwritten as the the one diff. I'm going to go trough the files and see how far behind I am - I know I moved files to a staging server so maybe theres files there I hand tweaked which hadn't got committed, I could replace my local files with. I appreciate your time on this with me, and I with I could give you more points here. But warm hug and a big thank you for your help is all I have from here :) – Richard Testani Oct 15 '16 at 14:18
  • @RichardTestani Ah, I'm confused by that. Anyway, the changes are in stash, that's for sure. You've probably crippled the local repo somehow (may be easy to get back, I just don't see it), so there's another option - [stash -> .patch file](http://stackoverflow.com/a/22819771/5994041) and apply the patch after you fix your repo. If you're not sure what stash(if there's more than one) DUMP EVERY STASH TO PATCHES to prevent loss of data when fixing the local repo. – Peter Badida Oct 15 '16 at 14:21