Home > database >  How to recover from detached (because of accidental pull)?
How to recover from detached (because of accidental pull)?

Time:12-25

I created a commit and instead of pushing I ended up pulling from main, after that I got some conflicts and made another mistake by skipping the rebase.

My git reflog has this:

1cc9f3f (HEAD, main) HEAD@{0}: checkout: moving from dabea28f2cce09575b49da21868098f4df8ebb94 to 1cc9f3f
dabea28 (origin/main, origin/HEAD) HEAD@{1}: checkout: moving from main to dabea28
1cc9f3f (HEAD, main) HEAD@{2}: rebase finished: returning to refs/heads/main
1cc9f3f (HEAD, main) HEAD@{3}: commit: Merge?
cea642f HEAD@{4}: pull --progress --no-edit --no-stat --recurse-submodules=no origin: Version 2.33.1
dabea28 (origin/main, origin/HEAD) HEAD@{5}: pull --progress --no-edit --no-stat --recurse-submodules=no origin: checkout dabea28f2cce09575b49da21868098f4df8ebb94
4fc10c5 HEAD@{6}: commit: Support for multiple architectures.
96ca30f HEAD@{7}: reset: moving to HEAD
96ca30f HEAD@{8}: commit: Version 2.33.1
dabea28 (origin/main, origin/HEAD) HEAD@{9}: commit: Version 2.33
466448e HEAD@{10}: commit: Version 2.32
7d89f20 HEAD@{11}: commit: Version 2.31

I wanted go back to my changes that are available in 4fc10c5 HEAD@{6} so that I can push to main. What do I do to undo these last changes and just continue pushing Head@{6}?

Basically, I lost all my changes after HEAD@{5}, when I git pull and git rebase -skip instead of git push.

I did copy all files manually by accessing the detached using git checkout 4fc10c5, just in case.


Status:

$ git status
On branch main
Your branch is ahead of 'origin/main' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

enter image description here


After git reset --hard @{5}:

7d89f20 (HEAD -> main) HEAD@{0}: reset: moving to @{5}
1cc9f3f HEAD@{1}: checkout: moving from 4fc10c53d572616e4524f77d51a2cb556218bbbf to main
4fc10c5 HEAD@{2}: checkout: moving from 1cc9f3f80292dbd76e78f52cf8ea011cd4610801 to 4fc10c5
1cc9f3f HEAD@{3}: checkout: moving from dabea28f2cce09575b49da21868098f4df8ebb94 to 1cc9f3f
dabea28 (origin/main, origin/HEAD) HEAD@{4}: checkout: moving from main to dabea28
1cc9f3f HEAD@{5}: rebase finished: returning to refs/heads/main
1cc9f3f HEAD@{6}: commit: Merge?
cea642f HEAD@{7}: pull --progress --no-edit --no-stat --recurse-submodules=no origin: Version 2.33.1
dabea28 (origin/main, origin/HEAD) HEAD@{8}: pull --progress --no-edit --no-stat --recurse-submodules=no origin: checkout dabea28f2cce09575b49da21868098f4df8ebb94
4fc10c5 HEAD@{9}: commit: Support for multiple architectures.
96ca30f HEAD@{10}: reset: moving to HEAD
96ca30f HEAD@{11}: commit: Version 2.33.1
dabea28 (origin/main, origin/HEAD) HEAD@{12}: commit: Version 2.33
466448e HEAD@{13}: commit: Version 2.32
7d89f20 (HEAD -> main) HEAD@{14}: commit: Version 2.31

CodePudding user response:

if there's anyway to go back to HEAD@{5}

You can reset your branch to that commit, and then push (this time)

git reset --hard @{5}

Check then first if what you see if what you had, before the pull (instead of push)

CodePudding user response:

Using git rebase 4fc10c5 did the job.

enter image description here

Now I'm at pre-accidental-pull again.

  •  Tags:  
  • git
  • Related