Zhenchuan Ren
Zhenchuan Ren

Reputation: 27

I lose my commit when changes origin branch locally

My operation is :

  1. git pull
  2. git checkout origin/a
  3. changes some code
  4. git add.
  5. git commit -m "fix: save my changes"
  6. git checkout b
  7. git checkout origin/a

and I found my changes disappeared.

Upvotes: 1

Views: 33

Answers (1)

VonC
VonC

Reputation: 1323973

When you checkout (using git switch by the way) origin/a, you are in detached head mode.

You should:

  • git switch a to create a local branch a linked to origin/a
  • git branch -avv to check a exists, and has origin/a as upstream
  • git reflog to find the commit you have done
  • git cherry-pick <sha1> to get that commit on your branch a

Upvotes: 1

Related Questions