简体   繁体   中英

What's the best way to find old detached HEAD after repo sync?

假设当前分离的HEAD上有一些本地提交(A,A1,A2,A3)指向提交A,在repo同步之后,本地分离的HEAD被指向提交B的远程最新分离的HEAD覆盖,什么是找到旧提交(A,A1,A2,A3)的最佳方法?

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 .

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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM