Home > Software engineering >  What's the best way to find old detached HEAD after repo sync?
What's the best way to find old detached HEAD after repo sync?

Time:05-27

Say that there are some local commits(A, A1, A2, A3) on the current detached HEAD which points to commit A, after repo sync, the local detached HEAD is overridden with the remote latest detached HEAD which points to commit B, what's the best way to find the old commits(A, A1, A2, A3)?

CodePudding user response:

The simplest way I can imagine is:

  1. git reflog to find A:
HEAD@{1}: checkout: moving from A to B
  1. Then you can do anything to A, like
  • create a new branch for it in case missing it again: git switch -c branchname A, or
  • rebase or merge it to the current HEAD: git rebase A/git merge A, then you will see all A, A1, A2, A3 appear on the current HEAD once all conflictions(if any) are resolved, and don't forget to create a new branch with git switch -c.

CodePudding user response:

If there were no additional operations that moved HEAD around, you could use HEAD@{1} to know the exact previous location of HEAD before current. Can use different numbers, of course:

git log HEAD@{1}
  • Related