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)?
Asked
Active
Viewed 128 times
0
-
What do you run to `repo sync`? Cause `detached HEAD` won't just `pull` as it would not have an upstream branch to look at. – eftshift0 May 27 '22 at 05:50
-
`repo sync` is a command which fetches and checkout to the latest remote update, check here: https://source.android.com/setup/develop/repo – Chen Li May 27 '22 at 06:19
-
it simply checkout your HEAD to the remote's latest branch-less commit, aka, detached HEAD. – Chen Li May 27 '22 at 06:21
-
Oh, I C..... so, it's a wrapper-or-script that could be running a bunch of things. – eftshift0 May 27 '22 at 06:21
-
yup, that's it. – Chen Li May 27 '22 at 06:22
2 Answers
0
The simplest way I can imagine is:
git reflog
to find A:
HEAD@{1}: checkout: moving from A to B
- 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 allA, A1, A2, A3
appear on the current HEAD once all conflictions(if any) are resolved, and don't forget to create a new branch withgit switch -c
.

Chen Li
- 4,824
- 3
- 28
- 55
0
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}

eftshift0
- 26,375
- 3
- 36
- 60