0

So far, nothing has allowed me to screw stuff up wholesale like git. I keep hoping that I'm over the hump of the learning curve, and then here I am with something completely new...

I created a new git repo to begin version controlling my homeassistant config. I didn't want everything going up so I created a .gitignore file. In messing with the .gitignore I was experimenting with a couple of different options, the first of which disallowed everything, then added back specific file types. The second only disallowed a slightly broader set of files. During the messing with the .gitignore I made a couple of commits and attempted a push to github, which rejected my push because of a large database file. I added the database file to the .gitignore, and I believe, switched to the second version of the .gitignore, then did a pull. At some point I then noticed that all my files that were not covered by the .gitignore patterns have now disappeared.

I've tried checking out some of my initial commits before files started disappearing, and nothing has returned. Really, I'd just like to get back to the state before I initialized the repo, everything has really been downhill from there. I feel like the files can't actually be gone, because I never did anything that feels like it should have deleted them, but I can't seem to get the repo to reveal them.

My session log is posted here if following my flailing helps to debug: https://github.com/alexholman/tale_of_woe/blob/master/session_log.txt

Looking through the log, line 638 is the first time I should have noticed that my file list had gotten significantly smaller.

I don't mean to be so down on git. It seems wonderful, and the people I know that use it well do some magical things with it. But right now its late, I'm tired, and I miss my files.

A Holman
  • 25
  • 3
  • 1
    You committed all your files to your local master branch with commit id `8795b0f`. Can you checkout that commit? `git checkout 8795b0f`. – Matt Feb 27 '18 at 04:29
  • For the record `git pull` fetches + merges changes from an upstream branch (i.e. somebody else made a commit and pushed it and you want to incorporate it in your local copy). It seems like you're the only one committing to your branch so I don't think you want to `git pull` ever. What I think you have done is tried to push your local branch (i.e. all your files just committed) to the remote, it failed, and then you pulled in the remote branch which was almost empty and nuked your local copy. You should still be able to find your files in your local branch but they are not pushed to the remote. – Matt Feb 27 '18 at 04:45
  • What you're describing sounds similar to what I did / experienced. My issue is with the last step, finding my files in the local branch? A simple ls gives only the remaining files. As does checking out earlier commits. Same for removing my .gitignore and checking out earlier branches. I agree that they have to be somewhere, I just don't know how to retrieve them. – A Holman Feb 27 '18 at 14:17
  • I'll give your `checkout 8795b0f` a shot when I get home. Thanks – A Holman Feb 27 '18 at 14:26
  • Actually I think `git reset --hard HEAD~2` was your destructive operation. The `git pull` wouldn't have wiped out anything on your local branch. – Matt Feb 27 '18 at 21:47
  • See [this answer](https://stackoverflow.com/questions/5788037/recover-from-git-reset-hard) for how to recover from `git reset --hard`. Try `git reflog show` for starters. – Matt Feb 27 '18 at 23:10
  • Thanks, the checkout 8795b0f seems to have worked. If you want the imaginary internet points, cut and paste some portion of that into an answer and I'll mark it as best. Otherwise, thanks for your help. – A Holman Mar 06 '18 at 14:35

0 Answers0