Home > Mobile >  I accidentally run `git branch <branchA> <branchB> -f` and can't go back to previou
I accidentally run `git branch <branchA> <branchB> -f` and can't go back to previou

Time:01-17

I accidentally run git branch <branchA> <branchB> -f and can't go back to previous state... As a result of that, I received too many changes...

I originally wrote the architecture using Draw.io in a branch I created a long time ago. When I thought it was time to merge it, I couldn't do it because I got the following message.

There isn't anything to compare. master and document/initial-architecture are entirely different commit histories.

enter image description here

So I looked at this URL (enter image description here

And here is the result of git reflog.

enter image description here

CodePudding user response:

git reflog might save you if you haven't made too many moves since.

git reflog shows your movements rather than your branches history, find the SHA of the last good place and git reset --hard _YOUR_SHA_.

YMMV.

CodePudding user response:

git branch -f branchA branchA@{1}

See the reflog syntax in git help revisions.

The @{1} syntax is the pretty-much-universal backout from oopses like this.

Shell history expansion (introduced by !) has a "current line" marker #, and a "last word" selector $, making the totally-unnecessary-here shorthand for repeating the branch name

git branch -f branchA !#$@{1}

which I like too much to not mention.

  • Related