0

I had directories and files that I created since a specific commit, and found out that they weren't pushed to my repo for some reason.

I committed everything in my code base with -a and pushed it. Then I got an error once that said that my local branch is behind the remote branch for some reason, so I push -f-ed it.

Now all my new files are gone and my local codebase has reverted, and I don't have any clue why. I didn't pull anything from the server. I did use diff once, but just to view the changes between a local branch and a remote branch.

I'm sure that somewhere a past snapshot of my codebase is saved somehow in the refs.

How can I check if it is, and if it is, how can I revert it?

Edit: the issue I have does not require to revert to previous HEAD locations as there was a problem with a few previous commits themselves. Please remove the "duplicate" tagging.

Update: I think that I found that those untracked files were saved as either dangling blobs or unreachable objects. I'm currently checking this direction.

Gal Grünfeld
  • 800
  • 3
  • 9
  • 32
  • Something doesn't sound right here. Perhaps you shouldn't have done a `push -f` - it is normal for local branches to be behind the remote branch if somebody else has pushed commits into it. You should have used `git pull --rebase` to replay your commits after them. It sounds as though you have rewritten the remote branch's history, potentially losing other people's work. But that doesn't explain why your codebase has been lost. As @Shakil suggested, use `git reflog` and share the output here if you're not sure what to do with it. – RobMasters Feb 27 '19 at 10:52
  • `git commit -a` is a foot-shooter. Use it only when you're absolutely sure. Which means never. (Okay, slightly overstated for emphasis, but in this case a `git status` after a classic `add` could have shown your files listed for deletion for example.) – Romain Valeri Feb 27 '19 at 10:53
  • I'm the only developer working on a single bbranch (mostly using my repo as a backup for my local code), so I'm entirely sure what's supposed to be uploaded. And I did a `push - f` just because I didn't see that my code got uploaded on the remote branch. And I've used the exact same git commands so I don't know what got screwed up. My local branch was ahead, not behind, in actual code and changed. So I shouldn't use `pull`. – Gal Grünfeld Feb 27 '19 at 11:15

1 Answers1

1

You can try git reflog link and can check all of your actions in your current .git. Even if you want to check in your previous action log you can simply checkout to that action's SH1.

Shakil
  • 4,520
  • 3
  • 26
  • 36