0

I am trying to revert hard reset in my local branch

I was trying to commit changes to github repository. But it said your current branch is behind. I found hard reset option. I did hard reset after i pulled and pushed files but it changed all files to files in github repo. I lost all the local changes.gitdash-1 gitdash-2 gitdash-3 here is the deleted files i wanna get them back

phd
  • 82,685
  • 13
  • 120
  • 165

1 Answers1

1

If you would like to get your branch on a revision where it was before, and assuming you have no way in front of you to get the Id of the old tip of the branch (another branch, the terminal output when you where doing operations, some of which show ids of revisions), you can always check git reflog where you can see the ids of the revisions where HEAD has been. If you see the ID of the revision you want a branch to be, then git branch -f some-branch some-id or git reset --hard some-id (if the branch is already checked out).

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • i am afraid to do git reset again. I did git branch it says cannot force update the current branch – Rufat Aliyev May 18 '19 at 23:54
  • Sure.... git is telling you that it won't move the branch pointer of the branch you are working on right now. If there's no pending work laying around (uncommitted files and stuff) there's no reason to be afraid of `git reset --hard`. Anyway, you can detach if it makes you feel safer: `git checkout --detach && git branch -f the-branch the-id && git checkout the-branch`. Same thing. – eftshift0 May 19 '19 at 01:06
  • Yeah i did checkout to the HEAD name and it worked. thanks a lot – Rufat Aliyev May 19 '19 at 01:32