0

I did a first commit to a branch with fetch. I lost everything and git didn't push the new files to respository.

Is there anyway to recover my local folder? git fetch && git checkout 1.1.0

That's the command I ran that deleted everything from disk.

git reflog

enter image description here

i tried reset --hard with all the heads,non is taking me back to all deleted files.

Community
  • 1
  • 1
LearnToday
  • 2,762
  • 9
  • 38
  • 67
  • Assuming there's nothing more to this question than what is stated, this is normal behavior. Your last command there, `git checkout 1.1.0` checked out a tag or a branch with that name, which also includes rearranging your working directory to have the state of that tag/branch. This includes removing files not present in that tag/branch, adding files that are present, and overwriting files that are present both in the commit you went from and the tag/branch you went to. See the duplicate link on how to get back to where you were. – Lasse V. Karlsen Dec 10 '18 at 14:19
  • Additionally, you should read or watch some tutorials on how git works to get a more complete picture of what git does and why. – Lasse V. Karlsen Dec 10 '18 at 14:20
  • Actually, it's a new local folder. And I just tried to add the remote origin, So basically, every new thing I did was wipe out. I am not sure, if it's even possible to recover – LearnToday Dec 10 '18 at 14:24
  • If you created a new git repository, committed some files, added an (unrelated) remove, fetched from it, checked out a tag/branch from that remote, then your original commit is still in your repository so follow the duplicate link to see how to get back to where you were. – Lasse V. Karlsen Dec 10 '18 at 14:35
  • I have all of this ```53a0812 (HEAD -> 1.1.0, origin/master, origin/1.1.0) HEAD@{0}: reset: moving to origin/master d31c3e4 HEAD@{1}: reset: moving to HEAD~ 53a0812 (HEAD -> 1.1.0, origin/master, origin/1.1.0) HEAD@{2}: reset: moving to HEAD 53a0812 (HEAD -> 1.1.0, origin/master, origin/1.1.0) HEAD@{3}: checkout: moving from master to 1.1.0 d356b07 (master) HEAD@{4}: commit: Update started 5072991 HEAD@{5}: commit (initial): initial commit``` but non is taking me back to where I was before I did the fetch. – LearnToday Dec 10 '18 at 14:42
  • Please post additional information in the question itself. – Lasse V. Karlsen Dec 10 '18 at 14:43
  • i did post to the original answer – LearnToday Dec 10 '18 at 14:50
  • Any chance you could post the output as text and format it as code? Right now it's pretty unreadable. – Lasse V. Karlsen Dec 10 '18 at 14:52
  • i added a photo to make it clear to read – LearnToday Dec 10 '18 at 14:55
  • You should be able to do `git checkout master` to get back to where you were. Before you experiment any further, I advise you to make a full backup of your local repository folder (that is, working directory + .git directory), that way you cannot permanently destroy anything not already destroyed. – Lasse V. Karlsen Dec 10 '18 at 14:56
  • i get this `error: The following untracked working tree files would be overwritten by checkout:` but that's few of the files – LearnToday Dec 10 '18 at 15:00
  • i just have to start over again. thanks for your help. – LearnToday Dec 10 '18 at 15:03
  • Before you venture forth into new projects, do yourself a favor and read up on how git works, none of the error messages are wrong or problematic, but if you don't know what they mean and how to react to them, they're going to pose an impenetrable wall and you're going to be stuck at this wall again and again. – Lasse V. Karlsen Dec 10 '18 at 20:42
  • The last error you commented with simply means you have untracked files that will be overwritten when you change to a different commit, that's usually not a problem, at least not if you don't care about *the current state* of those files, but if you have no idea what those files contain, why they are untracked, what "untracked" means or why they will be overwritten, then git is going to be like magic, and this won't change. – Lasse V. Karlsen Dec 10 '18 at 20:43

0 Answers0