简体   繁体   English

回购同步后找到旧分离 HEAD 的最佳方法是什么?

[英]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: git reflog找到 A:
HEAD@{1}: checkout: moving from A to B
  1. Then you can do anything to A, like然后你可以对A做任何事情,比如
  • create a new branch for it in case missing it again: git switch -c branchname A , or为它创建一个新分支以防再次丢失: git switch -c branchname A ,或
  • 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 . rebase 或将其合并到当前 HEAD: git rebase A / git merge A ,一旦所有冲突(如果有)得到解决,您将看到所有A, A1, A2, A3出现在当前 HEAD 上,不要忘记使用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.如果没有移动 HEAD 的其他操作,您可以使用HEAD@{1}了解 HEAD 在当前之前的确切位置。 Can use different numbers, of course:可以使用不同的数字,当然:

git log HEAD@{1}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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