1

I'm very new to this git thing, and as far as my experience goes, I've never encountered something like this before.

I've multiple local branches that I frequently switch around with, since I work with a group, and use other branches as a reference.

In this case, one of my friends committed and pushed something to his branch, and he suggested we have a look-see.

So I committed my changes on my own branch, but as usual, there are those Xcode files that magically edit themselves whenever we just open them, so I thought it would be a good idea to just git stash them (after the commit) and deal with them later, just so I can checkout my friend's branch and fetch the update.

After that was done, I switched back to my branch, and did git stash pop, and checked-out said files that aren't really important.

Then I noticed the files I created are gone.

I tried to do a git revert but it did nothing, not that I understood what happened, anyway.

Here's the list of commands I put in:

git add Integra-Geochemistry/Controllers/WaterSamplingFormOneViewController.swift
git add Integra-Geochemistry/Views/WaterSamplingFormOneView.swift
git add Integra-Geochemistry/Xibs/WaterSamplingFormOne.xib
git status
git commit -m "Initial commit - added WaterSamplingForm"
git status
git branch
git branch dev/surface-thermal-sampling
git checout dev/surface-thermal-sampling
git checkout dev/surface-thermal-sampling
git stash
git status
git checkout dev/surface-thermal-sampling
git pull origin dev/surface-thermal-sampling
git branch
git status
git branch
git checkout dev/watersampling
git status
git stash pop
git checkout Integra-Geochemistry/Xibs/AddRadonFormView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormFourView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormThreeView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormTwoView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormView.xib
git log
git revert 63947089d3479fff91ae4fb2ba5d59bd39d0c30d

For reference, here's the log file (after I did the git revert)

commit 8f5a3b8a4db5bad0a750ba08cd2d5b6a8a2fe18e
Author: <-------->
Date:   Tue Jan 5 17:28:19 2016 +0800

    Revert "Initial commit - added WaterSamplingForm"

    This reverts commit 63947089d3479fff91ae4fb2ba5d59bd39d0c30d.

commit 63947089d3479fff91ae4fb2ba5d59bd39d0c30d
Author: <-------->
Date:   Tue Jan 5 17:13:35 2016 +0800

    Initial commit - added WaterSamplingForm

I've done a lot of committing, pushing and switching branches, but I never had anything disappear on me like this.

Is there any chance my files are okay and recoverable? I'd hate to start over. Thanks.

zack_falcon
  • 4,186
  • 20
  • 62
  • 108

1 Answers1

0

Is there any chance my files are okay and recoverable? I'd hate to start over. Thanks.

Yep.

type git reflog and checkout the desired commit that you want to get back to.

Basically every action you perform inside of Git where data is stored, you can find it inside of the reflog.

Git tries really hard not to lose your data, so if for some reason you think it has, chances are you can dig it out using git reflog.

What this means is that you can use it as a safety net: you shouldn’t be worried that a merge, rebase, or some other action will destroy your work since you can find it again using this command.

enter image description here

Read more about it here

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Thanks for the suggestion. The files I made still don't show up in Xcode, nor are they in their respective directories, though. I checked the other branches, they're not their, either (log stops at the point before "Initial commit - added WaterSamplingForm"). – zack_falcon Jan 05 '16 at 09:55
  • As a good practice, don't use stash use branches instead. If yu have not committed your files and you might want to try recover them using fsck. http://stackoverflow.com/questions/34572728/lost-all-my-staged-but-uncommited-modifications-after-git-revert-abort-command/34572818#34572818 – CodeWizard Jan 05 '16 at 09:58
  • I did commit the files ("Initial commit - added WaterSamplingForm"), I just didn't want to go through checking out or ignoring files that I didn't need (for some reason, viewing a xib in Xcode means you make changes to it or something). I tried fsck, but they still won't show up. – zack_falcon Jan 05 '16 at 10:05