0

I created a branch

git checkout -b myBranch

I made 3 commits onto the branch, lets name then One, Twoand Three.

I did an interactive rebase.

git rebase -i origin/master

With

pick One
drop Two
drop Three

and after dropping Two and Three I did a force push:

git push -f

I lost access to the local branch and just have access to origin.

Gitlab shows the hash ID of 'Three'. Still even I am not able to checkout the Three commit being child of Two.

After a new clone of the branch git reflog does not show relevant commit of Three. I assume because the history has changed on origin.

Jan Hackenberg
  • 481
  • 3
  • 14
  • Have you looked into `git reflog`? https://git-scm.com/docs/git-reflog – grottenolm Mar 27 '23 at 15:00
  • Relevant git book chapter: https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery skip to "Data recovery". It covers virtually this exact scenario – Brian61354270 Mar 27 '23 at 15:00
  • 1
    feel free to use the commit id that you have to put your branch there: `git reset --hard the-commit-id` (make sure to not have uncommitted stuff laying around your working tree because that will discard those changes). – eftshift0 Mar 27 '23 at 15:01
  • 1
    Although `reset --hard` is a command to be treated with respect and should normally not be an everyday command. I would rather suggest rather starting with `git branch myBranch2 the-commit-id` and then after you have inspected the code/history (with `gitk --all &` for instance) and are really sure `myBranch2` is what you want, then you can run `git checkout myBranch; git reset --hard myBranch2` to reset `myBranch` to be `myBranch2`. – hlovdal Mar 27 '23 at 23:01

0 Answers0