1

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.

1 Answers1

1

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @ZhenchuanRen Great! Don't forget to read https://stackoverflow.com/users/6309/vonc?tab=answers – VonC Aug 20 '20 at 05:47